Search code examples
jquerymemory-leaksevent-handlingdispose

Does jQuery dispose events automatically on window unload


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();
});

Solution

  • 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.