This content has been marked as final. Show 3 replies
>>Do I need to delete the object when done, or will it be deleted in garbage collection?
evtObj is declared as a local variable to the function so it will be deleted automatically.
no in most of the cases it wont get deleted so use delete keyword explicitly to remove object and event from memory.
Thanks. When you say "remove the event", is this the same thing as removing the object?
** Is it the case that I have to manually remove an object (i.e. an object in OOP sense, of any any data type) when I create any object, or just those passed to eventhandlers? I should hope the latter, otherwise whenever I create any object (or anything) I'll have to delete it? That would be insane --. I used to program Macintosh, so if I'm being clear here, when you get an "Object" with myObj= new Object(), then myObj is actually a pointer to memory occupied by the Object, right? Same with any new "object", e.g. MovieClip, etc. But if the variable myObj falls out of scope, then the memory that it points to is released as well, right? Does this happen with MovieClips as well? (I programmed Macintosh about 15 years ago, and it seemed much less forgiving than Actionscript -- blow away the wrong pointer and all would crash)
** If I don't create the object, because I don't need it, what happens if I inadvertantly delete it at the other end (
delete undefined I guess it would be, which will fail silently?)
** If I remove the object, is the object that is being passed to me as a param a pointer to the same object that all listeners to the event broadcast are getting? That is, if I have two listeners to the same event, and I delete the object passed as a param in the first listener to receive the event, will the object be available to the second? (the timing of first/second not determined by me, but chance)
** I looked through my two Moock's for answers, and what I came up with was the above: that much garbage collection is automatic (if the variable, i.e. the "pointer", falls out of scope, the memory pointed, i.e the object itself, will be collected), but if the variable is being referred to, it won't be collected. But in the eventhandlers I originally posted, when the Event is broadcast with the Object as a parameter, won't the Object no longer be referred to and then it will be collected.