user2881621
user2881621

Reputation: 3

how clean memory in flash, i try removechild, null but memory do not clean

how clean memory in flash, i try removechild, null but memory do not clean.

var m:m_mc = new m_mc ();

addChild (m);    
clean.addEventListener(MouseEvent.CLICK, fl_clean);

function fl_clean(event:MouseEvent):void
{       
    removeChild (m);    
    m = null;
}

Upvotes: 0

Views: 344

Answers (2)

Fygo
Fygo

Reputation: 4665

How are you checking the memory exactly? What kind of object is 'm'?

That you set it to null doesn't mean that the memory will be recovered right away. You just achieved that the object is eligible for garbage collection. The garbage collector may or may not pick it up in its next cycle, you may never know and there is no way to say for sure. It will be picked up when the memory will be needed by the runtime or some other condition occurs that forces the garbage collector to pick it. In case you are using large bitmaps, you can use the .dispose() method on them to recover the memory right away. But the bitmap object itself will still persist in memory waiting for the garbage collector to pick it up when it 'decides' to do so.

Upvotes: 1

csomakk
csomakk

Reputation: 5497

Either use weakeventlistener parameter of addEventListener, or removeEventListener in fl_clean.

Upvotes: 0

Related Questions