Skip to main content

Bug Tracker

Side navigation

#13270 closed bug (notabug)

Opened January 19, 2013 05:18PM UTC

Closed January 19, 2013 05:21PM UTC

Last modified January 19, 2013 07:41PM UTC

Is this a memory leak bug, or poor coding?

Reported by: kevin.turner@coraltree.co.uk Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: git
Keywords: Cc:
Blocked by: Blocking:
Description

We are using jQuery 1.8.3 and have an application that is leaking memory badly in certain conditions. It is very difficult to track down, but I have a small snippet of html/script that seems to exhibit a leak (obviously this is not part of the app itself):

<div id=”test1”></div>
<script>
        gInterval=setInterval(function() {
            $('#test1').empty().append($('<div id="'+Math.random()+'"></div>'));           
        }, 1);   
        setTimeout("clearInterval(gInterval); console.log('done');", 30000);   
</script>

I am using Chrome's heap storage analyse developer tool to take snapshots as this runs. The memory usage creeps up steadily. After the 30 seconds has completed, the memory usage stays static, so there is no garbage collection taking place.

If you analyse the storage, the object type that increases the most is "String", and the majority of the Strings contain this sort of thing (thousands of them)

"<div id="0.0454548745457875455"></div>"

So it looks like the string used to generate the div that gets appended to "test1" is never getting destroyed.

I was under the impression that using $().empty() would safeguard me from memory leaks. How could I amend the example above to prevent this type of memory leak?

Attachments (0)
Change History (6)

Changed January 19, 2013 05:21PM UTC by dmethvin comment:1

resolution: → notabug
status: newclosed

Please ask for help on a forum to determine whether you have a bug. Also be aware that the current supported version of jQuery is 1.9.0, not 1.8.3. And finally, that is not a valid name for an ID attribute.

Changed January 19, 2013 05:30PM UTC by anonymous comment:2

Aren't you missing the point?

The id is not relevant.

The point is that if I create an element with $("blah"), append to to another element with $().append, then empty the element with $().empty, then a memory leak occurs.

I would have thought that would be a concern - not?

Changed January 19, 2013 05:35PM UTC by dmethvin comment:3

There a are three sentences in my reply.

Please ask for help on a forum to determine whether you have a bug.

You haven't done this yet, I assume.

Also be aware that the current supported version of jQuery is 1.9.0, not 1.8.3.

My intent here was to ask that you use 1.9.0 in the test case you post on the forum.

And finally, that is not a valid name for an ID attribute.

According to your reply I have missed the point. Perhaps, but it's always good to have a valid test case before chasing the other issues.

Changed January 19, 2013 06:00PM UTC by anonymous comment:4

Why the attitude? I am trying to help to possibly identify a memory leak, not inviting you to lecture me like a child.

  • Yes I have logged it on the forum previously without success - otherwise I wouldn't be here
  • Whether or not the id is valid is not relevant. I tried it with and without a valid id and the leak still occurred.
  • When we had the problem, 1.8.3 was the latest release. I was not aware that 1.9.0 existed until now.

However, I have tried with 1.9.0 and it appears to be OK - which is great news. The bad news is I cannot implement it without a full regression test - but at least I have a way forward.

Thanks

Changed January 19, 2013 06:06PM UTC by dmethvin comment:5

It's not like there's a giant customer service organization here, fewer than a half-dozen jQuery core developers have to triage these tickets and they're all volunteers. Your original post had no test case (just a code snippet) and you didn't mention you'd already asked on the forum.

Glad that the 1.9.0 version solved this problem. Before upgrading, please do read the release notes including the upgrade guide, and use the jQuery Migrate plugin to automatically identify any issues.

http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/

Changed January 19, 2013 07:41PM UTC by anonymous comment:6

<script src="http://code.jquery.com/jquery-migrate-1.0.0.js"></script>

Great tool btw! I am up and running already.