In one of my projects I was fighting with a memory leak the last couple of days (yes … “couple”) and I came to the conclusion that there might be an issue related to touch / scroll gestures. In the sample below I have two buttons. The first one creates a list view with one thousand rows, the second one removes it.
I made the following observations:
- when I click on “create” and immediately on “destroy” then everything will be garbage collected.
- when I click on “create” and use the scrollbar to scroll down and then click on “destroy” everything will be garbage collected.
- when I click on “create” and then use a gesture to scroll down (with my Mac Magic Mouse) then the garbage collection fails.
I have used jvisualvm that ships with the JDK and I use the “Sampler” tab to look at the heap space. I filter for the “TestItem” class and I can see that always those items are still in memory that were created for the last ListView after pressing the “create”