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?
Asked
Active
Viewed 51 times
0
1 Answers
0
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).

Gabe Sechan
- 90,003
- 9
- 87
- 127
-
Can it be passing an listeler to another activity? – ahmetvefa53 Oct 30 '18 at 18:27
-
If that listener was the Activity itself, a non-static subclass, or had a reference to the activity that would absolutely cause it. Passing a listener from one activity to another is... a bad idea at the least, usually a big mistake. – Gabe Sechan Oct 30 '18 at 18:28
-
ALso note that if you didn't know this and code to avoid leaks, you sometimes have more than one. If an object is leaked in multiple places you need to fix all the leaks before it gets fixed. – Gabe Sechan Oct 30 '18 at 18:29
-
https://stackoverflow.com/questions/53068236/memory-leak-with-interface-referance/53068506?noredirect=1#comment93036403_53068506 I mean. This question bro . Not self listener . For example initialize an anonymous class (implementing an interface functions ) and passing it to another – ahmetvefa53 Oct 30 '18 at 18:53