Skip navigation
Currently Being Moderated

Garbage Collection after 10 minutes?

Sep 24, 2012 7:07 AM

My app is gradually increasing in memory usage but after a number of minutes (around 10 minutes) of non-use the memory usage goes down to a more reasonable level. I am wondering if this is the behavior of Adobe's built in garbage collector and if there is anyway I can help to encourage the app/flash to shed off the memory quicker.

 

Here is a brief explanation of the app. The app has a number of categories. Each category has a playlist of thumbnail images. When you navigate to a category, the thumbnail images are downloaded. Each thumbnail image's bitmapdata is copied resized to fit the app's layout and the original bitmapdata and loader are disposed of. When the user goes to a new category, the resized bitmapdata is disposed of and then the next set of thumbnail images are downloaded and resized. (Also note: that the loader of any thumbnail images that were in the process of being downloaded from the previous category are closed.)

 

When the app first launches, the size of the app is around 12MB. During my testing of the app, I navigate to one category and then to 2-3 other categories. I select the same category multiple times. Looking at the flash profiler, I can see that the memory usage peaks and valleys - but  in an inconsistent manner. Sometimes it peaks and then valleys after selecting a new category. Other times it just peaks but does not valley after selecting a new category. Plus selecting the same category over and over may result in different peak/valley behavior. Eventually after about 30+ category changes, the memory usage peaks to about 30MB. It could go higher (or slightly lower) after selecting more categories after reaching that 30MB peak.

 

If I do not do anything and just let the app alone, eventually the app's memory usage falls to a more reasonable rate of about 13-14MB. There isn't a timer in my app that releases any memory/objects so I am unsure why there's a huge release of memory after time. I also noticed that once it reaches a certain level of memory usage, then it is easier for the memory usage to peak to that level even though it may valley to a considerable amount below that peak. I did a comparison between a valley and peak, and 98% of the loitering objects are bitmapdata objects.

 

What may be going on here? Why does the memory get released after some time of non-use? Is there a way I can encourage flash to release that memory much sooner?

 

thanks!

 
Replies
  • Currently Being Moderated
    Calculating status...
    Sep 24, 2012 7:36 AM   in reply to JAXIMFLASH

    I seem to remember that the Flash garbage collector could be a little erratic, you could try setting the variable that holds the downloaded thumbnails to null after you're done with it?

     

    So if you're holding them in an array you could loop through and set each value to null e.g.

     

    for(var i:uint = 0; i < yourArray.length; i++)

    {

    yourArray[i] = null;

    }

     

    Not sure if that will help but it's worth a try.

     
    |
    Mark as:
  • kglad
    62,091 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 24, 2012 7:58 AM   in reply to JAXIMFLASH

    you can't control when the flash player gcs ready objects except while testing.

     

    during testing you can use:

     

    System.gc();

     

    to trigger the first (mark) phase of gc. executing that a 2nd (and especially a 3rd) time after enterframe ticks will force a complete mark and sweep.

     
    |
    Mark as:
  • kglad
    62,091 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 24, 2012 8:15 AM   in reply to JAXIMFLASH

    again, if you have memory that can be cleared, to trigger the first (mark) phase of gc. executing that a 2nd (and especially a 3rd) time after enterframe ticks will force a complete mark and sweep.

     
    |
    Mark as:
  • kglad
    62,091 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 24, 2012 9:14 AM   in reply to JAXIMFLASH

    then you may not have objects readied for gc when you did that.

     
    |
    Mark as:
  • kglad
    62,091 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 24, 2012 11:48 AM   in reply to JAXIMFLASH

    gc doesn't occur at timed intervals. 

     

    when an object is created, if new memory is needed, the player checks all existing (in memory) objects and counts the number of references to that object. if an object has 0 references that object is marked for removal on the next frame tick.  at least, that's the way it is supposed to work.

     

    but i've found the actual behavior of the player can be quite a bit different, with regards to the above and everything else i've checked, than advertised.  and the exact behavior depends on the flash player version.

     

    with flash pro, you have to create your own memory checker to see what's in memory at any given time.  flash builder or flex may have better tools (than flash) for memory management.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points