Android Question Garbage Collector

Discussion in 'Android Questions' started by nibbo, May 28, 2015.

  1. nibbo

    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
  2. thedesolatesoul

    thedesolatesoul Expert Licensed User

    The only way is to make sure you release all of your references.
    Its possible you could be leaking something from your process globals.
    lemonisdead and Peter Simpson like this.
  3. eurojam

    eurojam Well-Known Member Licensed User

  4. nibbo

    nibbo Active Member Licensed User

  5. nibbo

    nibbo Active Member Licensed User


    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.
    Peter Simpson likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice