androidandroid-activitydeallocandroid-profiler

activity rotate deallocation


I have created a hello world simple activity and I started.I look at android profiler , When I rotate screen , in the heap (android profiler monitor) totally 2 MainActivity are shown . why first activity did not dealloc?


Solution

  • It may be there's no problem. Memory does not instantly deallocate in Java. Instead, memory deallocates when garbage collection is run. If there are no references going from a GC root object to the object, the garbage collector will collect it. So it could just be that garbage collection hasn't run yet.

    The other possibility is that you have a memory leak. In this case you have some object referencing the Activity that isn't ready to go out of scope yet. Common causes are observable subscriptions, threads, static variables, and non-static inner classes being passed to something that stays resident (like the framework itself).