Memory leak about ContentObserver

I am having a problem with memory leaks in my android app.

I am using startActivity from activity1 to activity2 and then returning activity1 by pressing the back button.repeat serval time, adb shell shows the RSS app is growing and cannot crash. finally the VM will be shut down.

Then I use MAT to find:

Leak Suspects» Leaks» Problem Suspect 1 Description
59 instances of "android.database.ContentObserver$Transport", loaded by "<system class loader>" occupy 1,569,864 (39.41%) bytes. 

Keywords
android.database.ContentObserver$Transport

 Reference Pattern
Class Name Shallow Heap Retained Heap Percentage 
class android.database.ContentObserver$Transport @ 0x40308cc0 0 0 0.00% 

      

but I never use this class. How can I find out the real reason?

+3


source to share


1 answer


Are you using any CursorAdapter? If it hasn't been initialized correctly, it might create it on the ContentObserver which will leak you.

You must use this constructor for CursorAdapter. Flag 0 will stop it from creating its own ContentObserver.



new CursorAdapter(context, cursor, 0) 

      

0


source







All Articles