Why does heap memory increase when re-launching an activity?

前端 未结 5 1081
悲哀的现实
悲哀的现实 2020-12-05 16:00

This question concerns memory in Android.

My method:

I have two activites, A and B. From A, I launch B like this:

Intent i =         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 16:24

    What i think is, its a typical java question. And killing an Activity does't mean that its associated objects should be removed from the heap, even if they are in lost land (their reference are null). because its completely dependent on virtual machine when it calls Garbage collector (Irrespective of you saying System.GC()). so when there the condition is like nearly out of memory it calls it and cleans it(cannot be sure again, may be immediately after their reference becomes null), So i don't think you should be worrying about it.

    edited: call setContentView(getApplicationContext);

    and where ever you are this keyword to pass a context, change it to this.getApplicationContext()

提交回复
热议问题