This is kind of long - don't know if anyone will bother to read it (don't know if I would), but been beating my head against this for over a day.
I have a problem where the first of a series of objects I create is not ever being deallocated. I'm removing event listeners from the object, using the localconnection hack, etc. and it works to immediately deallocate any object except the very first one.
Here is the background:
I originally had this application which was an mxml file consisting primarily of a huge mx:Script block of pure actionscript 3. The application was configured via an xml file, the name of which was passed into it from the html file at startup.
The change I made was to allow a new xml file to be subsequently loaded (and reconfigure the app), when a user clicked on a hyperlink to an xml file. To facilitate this, I took that entire aforementioned block of code out of the mxml file and put it in its own class, in an .AS file. Now the main mxml file is absurdly short - all it does is instantiate this new class in the mxml application declaration:
initialize="{new Rad_XF(this);}"
This new Rad_XF object contains all the old code previously found in the mxml file.
And now if a user clicks a link pointing to a valid xml file, the existing Rad_XF Object creates a new Rad_XF object, and the new Rad_XF object, after its initialized, deletes the old one. And this works to delete any previous Rad_XF object - except the very first one (the one intialized as above).
Here is the code in Rad_XF to create a new Rad_XF object if the user clicks a link:
private function txt_linkHandler(e:TextEvent):void {
if (getExt(e.text).toUpperCase() == "XML")
new Rad_XF(parent_app,this,e.text);
else
navigateToURL(new URLRequest(e.text),"_self");
}
And the code in Rad_XF to destroy the previous Rad_XF object:
if (rad_xf_prev) {
parent_app.removeChild(rad_xf_prev.CanvasSB);
parent_app.removeEventListener("enterFrame",rad_xf_prev.app_enterframe);
parent_app.removeEventListener("mouseFocusChange",rad_xf_prev.repeat_end);
parent_app.removeEventListener("activate",rad_xf_prev.app_activate_handlr);
parent_app.removeEventListener("deactivate",rad_xf_prev.app_activate_handlr);
parent_app.removeEventListener("mouseMove",rad_xf_prev.mouse_handlr);
parent_app.removeEventListener("click",rad_xf_prev.mouse_handlr);
parent_app.removeEventListener("doubleClick",rad_xf_prev.mouse_handlr);
rad_xf_prev = null;
try {
new LocalConnection().connect('foo');
new LocalConnection().connect('foo');
} catch (e:*) {}
}
There is no difference at all, either intended or thus far discernable, between that first object and all subsequent objects, and yet the first object won't be deleted though subseqent ones will. (I enclosed the above block in System.TotalMemory calls to confirm this.) The first object is initialized in the mxml file, but I tried moving that to an AS file - made no difference.
Here are the first few lines of the Rad_XF constructor:
public function Rad_XF(parent_app:Application, rad_xf_prev:Rad_XF=null, fnCFG:String = null):void {
this.parent_app = parent_app;
this.rad_xf_prev = rad_xf_prev;
parent_app is the mxml application. rad_xf_prev is the previous rad_xf object that ends up being deleted.
Just didn't know if someone would bother to read this and have some viable ideas. Or thought maybe the process of writing this might give me some additional ideas, but it didn't.
(Note: Rad_XF does not extend any existing actionscript or flex class - should it?)