Search code examples
javascripttwitter-bootstrapmemory-leaksbootstrap-affix

bootstrap affix plugin memory leak


These lines in the bootstrap affix plugin seem to cause a memory leak because the window gets a reference to the affix instance that's never released.

As a workaround I'm using this code to release the references when removing the affixed element from the DOM:

$(window)
    .off('scroll.bs.affix.data-api')
    .off('click.bs.affix.data-api');

Seems kind of hacky- is there a better way of doing this? Didn't see anything in the affix plugin docs.


Solution

  • I took @Carrie Kendall's recommendation and opened a bug report... well commented on a related bug report.

    https://github.com/twbs/bootstrap/issues/13655

    What we need in this case is a "destroy" method for the affix plugin and some documentation on the getbootstrap site so that people using the affix plugin in single page apps can avoid the memory leak pitfall when removing their affixed content.