[ 2 posts ]

lucas theisen

  • Joined: Wed Aug 31, 2011 8:20 am
  • Posts: 2
  • Offline
  • Profile

When to use destroy?

Post Posted: Wed Sep 28, 2011 1:54 pm
+0-
When should destroy be called? Does it ever get called automatically by YUI lifecycle? Does the page unload cause the YUI lifecycle to call destroy on all objects created during the page processing? I have been working under the assumption that I need to make all my own calls to destroy but that gets hairy when ajax calls replace sections of code that I had progressively enhanced. I have written up my example in stackoverflow (When to call YUI destroy?) due to the size limitation here.

Nick Husher

YUI Contributor

  • Offline
  • Profile
Tags:

Re: When to use destroy?

Post Posted: Wed Sep 28, 2011 7:45 pm
+0-
The answer by Tivac is basically correct. When the page unloads (i.e. you visit a new URL), all the memory for the page is cleaned up. Or it should be. Regardless, it stops being your concern whether the memory for a page remains allocated after the unload event has fired.

That said, if you're replacing content in the DOM dynamically in any way, you need to make sure to detach any event handlers you might have created on those parts of the DOM. Generally, pages aren't long-lived enough for this to be an issue unless you're attaching horrific numbers of event handlers.
  [ 2 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum