Android : Memory leak with a HashMap on Android

on Monday, September 29, 2014


I'm trying to fix a memory leak that I'm not understanding how it happens, maybe with your help I could get to the solution. I have a ListFragment and a FileInfo class that stores the data for each list item. In this FileInfo class (it's to big to post it here) I have following:



public static final HashMap<String, FileInfo> sFileInfoObjectList = new CacheLinkedHashMap<String, FileInfo>();


I use this cache so I must not construct each FileInfo again each time. Each time my ListFragmnet get's reloaded FileInfo.getFileInfo(...) is called, if the FileInfo is in the cache it is returned, otherwise a new one is constructed. As I can see with DDMS, the heap of the Application is growing each time the ListFragment gets reloaded. Why am I sure that sFileInfoObjectList is leaking? Because when I call sFileInfoObjectList.clear() in the onDestroy() method of the ListFragment the heaps does not grow. I also checked the size of sFileInfoObjectList to see if it is growing but it's not, so this is really confusing for me now.


0 comments:

Post a Comment