Here is something more for you to chew on:

If you assign say an onLoad method to an object, and don't delete the onLoad
before you delete the object, the onLoad method is orphaned and since the
reference to the object is gone, it does not get cleaned up by the garbage
collector, and remains in memory with no way to get to it.

For example (AS1 code used here):

foo = new XML();
foo.onLoad = function(valid) {
        if (valid) {
                // xml loaded successfully
        } else {
                // xml load error
        }
}

If you:

delete foo;

the foo.onLoad method stays in memory.

You have to

delete foo.onLoad;
delete foo;

to really get rid of foo.

Objects cannot delete themselves, nor can they call another object to delete
them because technically you're still in the same operation thread.  It has
to be done independantly outside the object you're trying to delete.

The way I get around this is:

xmlHolder = {};
var id = new Date.getTime();
xmlHolder[id] = new XML();
xmlHoLDer[id].onLoad = function(valid) {
        if (valid) {
                // xml loaded successfully
        } else {
                // xml load error
        }
        this.complete = true;
}

I assign a complete = true property.  Then, I have my own little clean up
tool running, checking for complete xml loads:

for (var o in xmlHolder) {
        if(this.xmlHolder[o].complete) {
                delete this.xmlHolder[o].onLoad;
                delete this.xmlHolder[o];
        }
}

The clean up tool is running in a separate thread therefore it can delete
other xmlHolder without issue.

HTH,
Steven

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to