Alex: I will try two things
Here is a link to the clearModuleEvents and related code; https://hastebin.com/giqohitado.js Here is a link to the clearEvents and related code; https://hastebin.com/arilidifol.cs Here is the clearModuleEvents code pasted differently; public function clearModuleEvents(mdlModule:UIComponent):void { trace('Starting clearModuleEvents') for(var idx:int = mdlModule.numChildren - 1; idx >= 0; idx--) { trace('idx=' + idx + ' isContainer(objChild)=' +isContainer(objChild) + ' isContainer(mdlModule.getChildAt(idx))=' + isContainer(mdlModule.getChildAt(idx))); var objChild:DisplayObject = mdlModule.getChildAt(idx); trace('flash.utils.getQualifiedClassName(objChild)=' + flash.utils.getQualifiedClassName(objChild)); var childContainer:DisplayObjectContainer = objChild as DisplayObjectContainer; clearChildEvents(childContainer); childContainer = null; if ("clearEvents" in objChild) { var fncClearEvents:Function = objChild["clearEvents"]; if (objChild.hasOwnProperty('id')) trace('Clearing Events in==>>' + objChild['id']); fncClearEvents(); fncClearEvents = null; } if ("dataProvider" in objChild)objChild["dataProvider"] = null; if ("selectedIndex" in objChild)objChild["selectedIndex"] = -1; if ("selectedItem" in objChild)objChild["selectedItem"] = null; if ("value" in objChild)objChild["value"] = null; if ("text" in objChild)objChild["text"] = null; objChild = null; } objChild = null; trace('Finished clearModuleEvents') } private function clearChildEvents(dpsContainer:DisplayObjectContainer):void { for(var idx:int = dpsContainer.numChildren - 1; idx >= 0; idx--) { var objChild:DisplayObject = dpsContainer.getChildAt(idx); if (isContainer(objChild)) { var childContainer:DisplayObjectContainer = objChild as DisplayObjectContainer; clearChildEvents(childContainer); childContainer = null; } if ("killMe" in objChild) { var fncKillMe:Function = objChild["killMe"]; if (objChild.hasOwnProperty('id')) trace('Killing Events in==>>' + objChild['id']); fncKillMe(); fncKillMe = null; } else if ("clearEvents" in objChild) { var fncClearEvents:Function = objChild["clearEvents"]; if (objChild.hasOwnProperty('id')) trace('Clearing Events in==>>' + objChild['id']); fncClearEvents(); fncClearEvents = null; } if ("dataProvider" in objChild)objChild["dataProvider"] = null; if ("selectedIndex" in objChild)objChild["selectedIndex"] = -1; if ("selectedItem" in objChild)objChild["selectedItem"] = null; // if ("value" in objChild)objChild["value"] = null; if ("text" in objChild)objChild["text"] = null; objChild = null; } objChild = null; } ---------------------------------------- From: Alex Harui <aha...@adobe.com.INVALID> Sent: 2/1/19 1:20 PM To: "users@flex.apache.org" <users@flex.apache.org>, "pa...@compuace.com" <pa...@compuace.com> Subject: Re: instances of objects magically appear... It was hard to read the code in the email. In the future, try using pastebin or some other service, or open a JIRA issue and put the code in there. I think I saw that a Dictionary was holding the children but it isn't a weak-reference dictionary, so that could pin those children in memory. HTH, -Alex On 2/1/19, 10:16 AM, "Paul Stearns" wrote: I am trying to solve my memory leak issue. I have added a clearEvents function to my testing modules. My thought is to execute this function prior to unloading each module. Towards that end I have created a function in the parentApplication called clearModuleEvents which recursively loops through each child, and if the "clearEvents " function exists, run it. Then I unload the module. Using the profiler when I execute clearModuleEvents, it seems to create another instance of each display object. I am not sure why. I would appreciate if someone might tell what might cause that. Here is the code referenced above; clearEvents & related code; protected var dctListeners:Dictionary = new Dictionary(); override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = true):void { var key:Object = {type: type, useCapture: useCapture}; if (dctListeners[key]) { removeEventListener(type, dctListeners[key], useCapture); dctListeners[key] = null; } dctListeners[key] = listener; super.addEventListener(type, listener, useCapture, priority, useWeakReference); } public function clearEvents():void { trace('TestMemoryLeak clearEvents'); try { for (var key:Object in dctListeners) { removeEventListener(key.type, dctListeners[key], key.useCapture); dctListeners[key] = null; } } catch (e:Error) { trace('TestMemoryLeak clearEvents error='+e.message); } dctListeners = null; } clearModuleEvents and related code public function clearModuleEvents(mdlModule:UIComponent):void { trace('Starting clearModuleEvents') for(var idx:int = mdlModule.numChildren - 1; idx >= 0; idx--) { trace('idx=' + idx + ' isContainer(objChild)=' +isContainer(objChild) + ' isContainer(mdlModule.getChildAt(idx))=' + isContainer(mdlModule.getChildAt(idx))); var objChild:DisplayObject = mdlModule.getChildAt(idx); trace('flash.utils.getQualifiedClassName(objChild)=' + flash.utils.getQualifiedClassName(objChild)); var childContainer:DisplayObjectContainer = objChild as DisplayObjectContainer; clearChildEvents(childContainer); childContainer = null; if ("clearEvents" in objChild) { var fncClearEvents:Function = objChild["clearEvents"]; if (objChild.hasOwnProperty('id')) trace('Clearing Events in==>>' + objChild['id']); fncClearEvents(); fncClearEvents = null; } if ("dataProvider" in objChild)objChild["dataProvider"] = null; if ("selectedIndex" in objChild)objChild["selectedIndex"] = -1; if ("selectedItem" in objChild)objChild["selectedItem"] = null; if ("value" in objChild)objChild["value"] = null; if ("text" in objChild)objChild["text"] = null; objChild = null; } objChild = null; trace('Finished clearModuleEvents') } private function clearChildEvents(dpsContainer:DisplayObjectContainer):void { for(var idx:int = dpsContainer.numChildren - 1; idx >= 0; idx--) { var objChild:DisplayObject = dpsContainer.getChildAt(idx); if (isContainer(objChild)) { var childContainer:DisplayObjectContainer = objChild as DisplayObjectContainer; clearChildEvents(childContainer); childContainer = null; } if ("killMe" in objChild) { var fncKillMe:Function = objChild["killMe"]; if (objChild.hasOwnProperty('id')) trace('Killing Events in==>>' + objChild['id']); fncKillMe(); fncKillMe = null; } else if ("clearEvents" in objChild) { var fncClearEvents:Function = objChild["clearEvents"]; if (objChild.hasOwnProperty('id')) trace('Clearing Events in==>>' + objChild['id']); fncClearEvents(); fncClearEvents = null; } if ("dataProvider" in objChild)objChild["dataProvider"] = null; if ("selectedIndex" in objChild)objChild["selectedIndex"] = -1; if ("selectedItem" in objChild)objChild["selectedItem"] = null; // if ("value" in objChild)objChild["value"] = null; if ("text" in objChild)objChild["text"] = null; objChild = null; } objChild = null; }