Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#13270 closed bug (notabug)

Is this a memory leak bug, or poor coding?

Reported by: kevin.turner@… 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?

Change History (6)

comment:1 Changed 7 years ago by dmethvin

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.

comment:2 Changed 7 years ago by anonymous

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?

comment:3 Changed 7 years ago by dmethvin

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.

comment:4 Changed 7 years ago by anonymous

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

comment:5 Changed 7 years ago by dmethvin

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/

comment:6 Changed 7 years ago by anonymous

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

Great tool btw! I am up and running already.

Note: See TracTickets for help on using tickets.