views:

543

answers:

2

For example on a page I have

$(document).ready(function()
{
    $('#some-element').click(function()
    {
       // do something..
    });
});

Do I also need to add the unbind code - or will jQuery automatically do this for me?

$(window).unload(function()
{
    $('#some-element').unbind();
});
+1  A: 

You shouldn't need to do that.

nickf
+1  A: 

If you're asking about when the page refreshes (e.g. user clicks a link or something), then it doesn't matter since the page/client-side code no longer exist at that point.

So, I wouldn't worry about unbinding something in that scenario.

deadbug
So no memory leaks you rekon?
Jake Scott
No, not in that scenario.
deadbug