mattbradley / livestampjs

A simple, unobtrusive jQuery plugin that provides auto-updating timeago text to your timestamped HTML elements using Moment.js.
http://mattbradley.github.com/livestampjs
MIT License
409 stars 70 forks source link

destroy doesn't remove the element causing memory leak #34

Open lostincomputer opened 9 years ago

lostincomputer commented 9 years ago

Memory is not freed when I call the destroy function

Root cause is this line: $livestamps = $livestamps.not($el);

basically, with .not(), the element isn't removed from the array. $livestamps still holds a reference to the element.

Code to reproduce the problem: $('#birth').livestamp(new Date('June 18, 1987')); $('#birth').livestamp('destroy'); $('#birth').livestamp(new Date('June 18, 1987')); $('#birth').livestamp('destroy'); $('#birth').livestamp(new Date('June 18, 1987')); $('#birth').livestamp('destroy');

You will notice that value of $livestamps.selector becomes longer and longer .not().not().not([object Object]) .not().not().not([object Object]).not().not([object Object]) .not().not().not([object Object]).not().not([object Object]).not().not([object Object])

philfreo commented 9 years ago

@mattbradley thoughts on this?

mattbradley commented 9 years ago

Very nice find. This seems to be another quirk with using jQuery's methods to manage the list of livestamps (similar to #16). Maybe just adding and removing the livestamps from an array would be better. I'll look into this for v2.0.