mc.onEnterFrame = function() {
    trace("hit");
    delete this.onEnterFrame;
}

Try this one on for size.  You'll only get one (1) "hit" trace out to the
output window.  If you have actions following the delete they'll still get
called before the method is deleted.

mc.onEnterFrame = function() {
    delete this.onEnterFrame;
    trace("hit");
}

you still get "hit" traced out once in the output window.

Cicak you're right: "if they have reference counting in place, they can
delete object the moment its ref count is zero"

This is the Flash Player garbage collection right now.  Gary Grossman gave a
great talk at the MAX conference explaining the difference between the
reference counting GC in the current player and the new GC coming in FP 8.5.
Because it's the reference counting system I'm afraid you can't delete an
object this way if there's other references to it.  The reason onEnterFrame
can delete itself is because it's deleting the single reference the system
has to it.

Solution:

since Flash takes care of garbage collection, you don't need special
clean-up procedures (this is why other languages have something like
"destroy")  Forget about OOP usuals and garner the strength provided by a
dynamic language (ie just say "delete myObj;" instead of the OOP required "
myObj.destroy();").

The more I develop the more I find that OOD (object oriented design,
designing your system well) is much more important than OOP (following all
the rules, applicable or not, for the sake of being as much like Java as
possible)

Tyler

On 12/4/05, Hans Wichman <[EMAIL PROTECTED]> wrote:
>
> ps boon, one fast way to verify on windows:
> - repeat your action 100000 times in a for lus with the taskmanager open
>
> If the memory you use is being recollected you will see your application
> eat memory and release it, eat it and release it etc if not, it will just
> be hogging memory until it hangs...
> quick and dirty ;)
>
>
> At 02:12 AM 12/4/2005, Boon Chew wrote:
> >Good stuff Steven, I am glad I asked this question (and David's reply is
> >great).
> >
> >   Is there a way to verify that the onLoad is indeed orphaned in the VM
> > memory pool?
> >
> >
> >   - boon
> >
> >
> >Steven Sacks <[EMAIL PROTECTED]> wrote:  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
> >
> >
> >
> >
> >---------------------------------
> >  Yahoo! Personals
> >  Skip the bars and set-ups and start using Yahoo! Personals for free
> >_______________________________________________
> >Flashcoders mailing list
> >[email protected]
> >http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to