Cleaning that up is not Jquery's job as far as I know but the JScript
garbage collector (which basically depends on the browser). The
garbage collector is pretty smart so it shouldn't be any leak...
serious leaks used to happen only on Circular References especially in
IE6 for example, but even that has been mostly fixed with patches.

Also I hope you are aware that if you do Step 2 then the click event
defined in Step 1 won't work on the elements in #container div
anymore. You'd have to add Step 1 again after Step 2.



On Dec 8, 9:13 pm, gotnoboss <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've got a question I was hoping someone could shed some light on for
> me.
>
> Suppose you have a div like so:
>
> <div id="container">
>     <input type="checkbox" name="check" value="1"> One <br/>
>     <input type="checkbox" name="check" value="2"> Two <br/>
>     <input type="checkbox" name="check" value="3"> Three <br/>
> </div>
>
> 1) Suppose you have bound a 'click' event to every checkbox in the
> above:
>
>     $("#container input).click(function() {alert('hi');});
>
> 2) Then, you carte blance replace all the html in the div as the
> result of an ajax request:
>
>     $("#container").html(htmlReturnedFromServer);
>
> What happens to the events registered in step 1?  Are they "leaked"?
> Does JQuery know to unbind them before replacing the HTML?  Does it
> even have to do that to avoid a memory leak?  Do I need to unbind them
> myself before replacing the HTML?
>
> Thanks for the insight,
> Erik

Reply via email to