RE: [Flashcoders] removeChild madness
cool... the dw = null; did the trick... THNX! I thought it was automatically deleted, because it is a local var, but it points to the actual MovieClip offcourse... Reminds me of the good old pointers in C++ :p -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Romuald Quantin Sent: Tuesday, 09 September 2008 14:48 To: 'Flash Coders List' Subject: RE: [Flashcoders] removeChild madness I'm not sure but I think you don't correctly remove the onEnterFrame Event. As you use the weakReference you miss the false in the remove method, you should remove it that way: removeEventListener(Event.ENTER_FRAME, onEnterFrame, false); If this doesn't solve your problem, I usually set the instance to null after a remove: removeChild(dw); dw = null; I hope it helps. Romu www.soundstep.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sander Schuurman Sent: 09 September 2008 12:18 To: Flash Coders List Subject: [Flashcoders] removeChild madness I know there's a lot written about the Garbage Collection, and removing assets in AS3... I'm trying to get my hands around it, but I'm still strugling ;) A simple example: I'm adding a MovieClip from the library, and I'm removing it as well, like a toggle. The MovieClip contains the System.totalMemory property. If I keep toggling the MC on and of... the memory keeps going up... I'm destroying the MC and removing it from the displayList... But it's not cleared from the memory. What Am I missing? ToggleCode: private function toggleDebug() :void { var dw:debugWindow_lib = getChildByName('debugWindow') as debugWindow_lib; if (dw == null ) { var debugWindow:MovieClip = new debugWindow_lib(); debugWindow.name = "debugWindow"; addChild(debugWindow); } else { dw.destroy(); removeChild(dw); } } Class public class debugWindow_lib extends MovieClip { public function debugWindow_lib() { addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true); } private function onEnterFrame( e :Event ) :void { var tM:Number = System.totalMemory / 1024; totalMemory.text = tM.toString(); } public function destroy() { removeEventListener(Event.ENTER_FRAME, onEnterFrame); } } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] removeChild madness
I'm not sure but I think you don't correctly remove the onEnterFrame Event. As you use the weakReference you miss the false in the remove method, you should remove it that way: removeEventListener(Event.ENTER_FRAME, onEnterFrame, false); If this doesn't solve your problem, I usually set the instance to null after a remove: removeChild(dw); dw = null; I hope it helps. Romu www.soundstep.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sander Schuurman Sent: 09 September 2008 12:18 To: Flash Coders List Subject: [Flashcoders] removeChild madness I know there's a lot written about the Garbage Collection, and removing assets in AS3... I'm trying to get my hands around it, but I'm still strugling ;) A simple example: I'm adding a MovieClip from the library, and I'm removing it as well, like a toggle. The MovieClip contains the System.totalMemory property. If I keep toggling the MC on and of... the memory keeps going up... I'm destroying the MC and removing it from the displayList... But it's not cleared from the memory. What Am I missing? ToggleCode: private function toggleDebug() :void { var dw:debugWindow_lib = getChildByName('debugWindow') as debugWindow_lib; if (dw == null ) { var debugWindow:MovieClip = new debugWindow_lib(); debugWindow.name = "debugWindow"; addChild(debugWindow); } else { dw.destroy(); removeChild(dw); } } Class public class debugWindow_lib extends MovieClip { public function debugWindow_lib() { addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true); } private function onEnterFrame( e :Event ) :void { var tM:Number = System.totalMemory / 1024; totalMemory.text = tM.toString(); } public function destroy() { removeEventListener(Event.ENTER_FRAME, onEnterFrame); } } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] removeChild madness
I know there's a lot written about the Garbage Collection, and removing assets in AS3... I'm trying to get my hands around it, but I'm still strugling ;) A simple example: I'm adding a MovieClip from the library, and I'm removing it as well, like a toggle. The MovieClip contains the System.totalMemory property. If I keep toggling the MC on and of... the memory keeps going up... I'm destroying the MC and removing it from the displayList... But it's not cleared from the memory. What Am I missing? ToggleCode: private function toggleDebug() :void { var dw:debugWindow_lib = getChildByName('debugWindow') as debugWindow_lib; if (dw == null ) { var debugWindow:MovieClip = new debugWindow_lib(); debugWindow.name = "debugWindow"; addChild(debugWindow); } else { dw.destroy(); removeChild(dw); } } Class public class debugWindow_lib extends MovieClip { public function debugWindow_lib() { addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true); } private function onEnterFrame( e :Event ) :void { var tM:Number = System.totalMemory / 1024; totalMemory.text = tM.toString(); } public function destroy() { removeEventListener(Event.ENTER_FRAME, onEnterFrame); } } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders