I will try to make this question as simple as possible for your sake and for mine
// this is how I create an instance of a level
_STAGEONE = new StageOne();
addChild(_STAGEONE);
//------
// this is how I remove it
if (_STAGEONE && _STAGEONE.parent)
{
_STAGEONE.parent.removeChild(_STAGEONE);
_STAGEONE = null;
}
Before I remove _STAGEONE, do I have to remove every reference and event listener from the instances that I use inside of it to avoid a memory leak?
I has a few buttons, a HUD, a vector or two and whatnot. Do I have to remove the references to all of those things before I remove the _STAGEONE, or is removing _STAGEONE in this manner enough?
If you need more code to help, I will absolutely provide it. I've been searching all day and reading about the GC and removing references and nulls and stuff. I can't seem to determine if this is correct.
Edit: Also, what should I be aiming for as far as memory usage?
My whole concern with this is that when I remove the HUD (ie the STAGEONE) and then put it back (I have it on a staggered loop for testing), the memory use stays the same for the first two or three cycles and then starts infringementing by roughly 100kb every time the HUD reappears. I'm not sure if this is normal and I'm not really sure if it's a memory leak either, since it would never actually loop like this, so I don't know!
Essentially it goes...
Create HUD: memory use is 18.402
Remove HUD: memory use is 18.211
Create HUD: memory use is 18.512
Remove HUD: memory use is 18.310
Create HUD: memory use is 18.660
loop forever