Using some ARP commands to help manage some Flashcom connection complexity. I’ve stuck the NetConnection on the Model (aka Cairngorm ModelLocator). Inside the command, I utilize a Delegate to point to a callback in the Command.
Model.nc.onStatus = Delegate.create(this, onNCStatus);
About 5 commands later, I was seeing a trace from that onStatus. Since commands are created as local variables in the CommandRegistry or CommandTemplate, they die after they are done since there are no more references to them once they call their callback function. This doesn’t necessarely mean garbage collection cleans it, but it does ensure it should eventually.
However, I forgot my Delegate function was creating a longer lasting link by mapping the NetConnection sitting as a static variable on the Model Singleton class. Since Model.nc wasn’t going anywhere since no one ever deletes him, the Command that held the callback function for it’s onStatus never left either. If I got an error message, I’d get a trace a few commands later, and was like, “WTF…?”.
So, now, I just clean it up via:
Model.nc.onStatus = null;
Whenever my command is done.
This is the 2nd time in 2 weeks I’ve gotten bitten by member references in local variables that co-chill on the Activation object to make them live like member variables; meaning, they don’t necessarely die at the end of their current function like you’d think they would.
When sharing data between 2 SWF’s, 1 of the objects in an array was referencing the loaded SWF; even though there weren’t any security restrictions because of same domain, this wreaked havoc on my code not getting values it was expecting; it’d get an array, but all the objects in it were undefined.
So, I just made true, deep copies manually. Sucked, but again, reason #35 billion squared for an Object.deepClone() intrinsic method.