Some times my adobe air application becomes very slow because garbage collector starts to work continiosly on each frame and takes more then 800% of budget. it lasts several minutes or even more. This problem appears only on iPhone 4/4s from time to time and after restarting device everything works correct for some time.
Maybe somebody also has such situation and know the ways how to prevent it?
UPDATE: object pools and other allocation-prevention approaches already implemented. So there's nothing really to collect and GC is just spending CPU for nothing. When this ends memory usage is still the same. Also it does not happen every time even if same input and scenario is used. So I suppose there's some 'unlucky' situation with allocated heap being around some threshold where AIR decides to make clean up before taking another chunk from the system. Then it found few objects to dispose and no new chunk is required again. On next frame few objects are created (very few) and scenario is repeated.
A few points to keep in mind:
var s:Sprite = new Sprite()
creates a reference to a Sprite
. var s2:Sprite = s
creates another reference. For the memory that your Sprite
takes to be considered for garbage collection, both s
and s2
need to be set to null. If they're local variables, this will happen automatically when they go out of scope (e.g. if they're declared in a function, at the end of the function)To help the GC:
destroy()
or a dispose()
method that you call when you want to get rid of something, and null
everything that's an objectBitmapData
and XML
can be immediately destroyed (BitmapData.dispose()
and System.disposeXML()
). If it's only used for setup, or can be reloaded, get rid of it. NOTE: if you're using Starling, and you create Textures
from Bitmaps
, then you probably don't need the original, unless you want to deal with lost contexts, but you can probably just load everything back in.cacheAsBitmap
is allocating a bitmap in the background, ditto for filters
; Array.splice()
is creating a new array etcI wrote a class ages ago to help track memory leaks (http://divillysausages.com/blog/tracking_memory_leaks_in_as3), but you should be able to get even more in-depth using Scout - take a memory snapshot, play around a bit, then take another one; you can compare the two and highlight any created objects, including (I think) where they're being created.
Another point to keep in mind is if your device actually has enough memory to run your app in the first place - e.g. if your app (assuming everything is optimised etc) takes 100MB of memory, but you only have 80MB available, the GC will be continuously running to try and allocate the last 20
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With