0
votes

There was many discussions about this problem, but I want to pay attention on the situations that IMHO seems not so clear:

Yes the general rules are: Remove chachedAsBitmap Stop movieClip if playing Remove events Delete references etc.

But let's look:

First Example: I have nested sprite (ex: mainSprite), it contains other sprites with dynamic textFields in it (and are chached as bitmaps), just textFileds and MovieClips with event listeners on it (with weak reference). When I need to remove this sprite I need first to remove all it's nested content via loops or just

removeChild(mainSprite);
mainSprite=null;

is just enough?

Second Example: I have some sprite in which I'm loading bitmap and manipulating with bitmapData, later I'm just replacing content of this sprite with another bitmap, is allocated memory for older bitmap automatically erases and is overwritten or it still exists?

Third example: I have some "graphics template" MovieClip (in library with Export for Actionscript property set on it) which I'm adding on the stage and filling with dynamic data (and adding event listeners), let's say that it's one scene of the app, on another scene I need same MovieClip with other dynamic data, but inbetween need to clear my stage (need something like transition animation which is also library MovieClip), what's the best way: to set this MovieClip visible property to false (while transition animation is plays) and then reuse it, or just remove it with removeChild and then add when add with addChild once more?

All I wrote is more about Air Mobile, cause in most cases for the desktop these situations aren't so problematic, but in case of mobile development they are.

2

2 Answers

1
votes

You can visually monitor memory usage along with fps etc using this lib: http://code.google.com/p/flash-console/

hope that helps.

P.S. gc in flash is always a weird thing :)

0
votes

First example: removing mainSprite from display list is enough if there are only weak listeners on its children. Second example: I'd advice reusing the same object with visible = false. Recreating the same object is more resource expensive plus you get another instance of the same thing being in memory before it gets gc'ed.