Android Question Garbage Collector

nibbo

Active Member
Licensed User
I think there is an issue with Garbage Collector when finishing activities.
I have a an ordering app with 10 'sections' in a 'catalogue'.
When clicking on a section an order activity starts which displays up to 200 items with an image for each.
The first section is OK and when finished with does do an Activity.Finish, I would have expected this to release it's resources?
I can do 5 or 6 different sections but eventually I get an out of memory error and the app crashes.
It does not matter what order I click the sections in it always gets an OOM eventually.
This is usually preceded by a few Downsampling image due to lack of memory: 8
But always a java.lang.OutOfMemoryError
This implies that Activity.Finish does not release the memory that it had used.

Is there a way to force the activity to release its memory?
It there a way to show the amount of free memory so that I could prove my theory?

PS I am using LoadBitmapSample(dir, image, 200, 140) to reduce the memory usage.
also, 16GB Galaxy tab 3 or 4 both fail (currently testing on the Tab 3, version 4.4.2).

Thanks for any help
 

nibbo

Active Member
Licensed User
SOLVED.

Not sure if what I have done is the best solution but is has worked...

I added Activity.RemoveAllViews before Activity.Finish which definitely helped a bit but it still crashed eventually.

I changed all LoadBitmapSamples to use the VBBitmap library which seems to prevent it crashing.

Just for good measure:
I called the Garbage method from this library before closing the activity.
I added SetApplicationAttribute(android:largeHeap, "true") to the manifest.

This seems to have stopped the OOM crash.
 
Top