madrobby / zepto

Zepto.js is a minimalist JavaScript library for modern browsers, with a jQuery-compatible API
http://zeptojs.com
Other
15k stars 3.91k forks source link

DOM event listeners leak with detached nodes #1169

Open antelle opened 8 years ago

antelle commented 8 years ago

I've noticed a leak of DOM nodes and attached listeners with zepto. Here's a simple case:

<div id="top"></div>
function doWork() {
    $('#top').html('<div title="test element" id="inner">testing</div>');
    $('#inner').click(cb);
    timeout = setTimeout(doWork, 1);
}
function cb() { console.log('callback'); }
doWork();

When capturing Timeline after running several minutes with Zepto I see the following: zepto Nodes are not collected by GC, references to them are somewhere inside Zepto, JS heap is increasing.

If I replace Zepto with jQuery: jquery With jQuery, listeners count is stable, nodes count is increasing during the capture but returns back to small amount after restrating the timeline, as expected, JS heap doesn't grow: this timeline was captured after several minutes, and you can compare the numbers with Zepto.

Zepto 1.1.6, jQuery 2.2.0, Chrome 48 (Mac OS X)

madrobby commented 8 years ago

@mislav What's your opinion on this?