I'm trying to crack down on a memory leak which is causing the heap to run out of memory and the GC to get invoked. A lot.
Logcat is filled with messages like this:
11-27 20:54:39.052: DEBUG/dalvikvm(32167): GC_CONCURRENT freed 405K, 5% free 11046K/11591K, paused 2ms+3ms
I used the DDMS Allocation tracker to see if there was anything in particular getting allocated more than usual, and the instant that I clicked the 'Get Allocations' button in Eclipse, the list was filled with java.util.AbstractList$SimpleListIterator They get allocated during the main game loop, so there are lots, and I believe this is what is eating the heap memory.(there are approx. 509 allocations of SimpleListIterator)
However, DDMS is telling me that they are being allocated wherever there is a for-each loop, which I think is strange. o_O
Normally I would use a regular for loop, but this article recommends using the for-each loop instead since it's faster, but it mentions nothing about its memory usage
Could all these allocations be the result of using the for-each loop instead of the regular for loop? (It'll take a while to go in and change every single for-each loop in my app, so I'd rather ask first) If they are, then is this normal? Is it a programming error on my part?
UPDATE I changed the for-each loops to regular for loops and the completely solved the problem. I still think its dumb though that I had to do that