Skip to main content

Bug Tracker

Side navigation

#8450 closed bug (worksforme)

Opened March 05, 2011 08:30PM UTC

Closed July 12, 2011 04:37PM UTC

Memory Leak when removing objects (leaving orphans)

Reported by: aking@isatec.co.uk Owned by:
Priority: high Milestone: 1.next
Component: manipulation Version: 1.5
Keywords: Cc:
Blocked by: Blocking:
Description

Using jQuery1.5 I am seeing orphans left in my DOM.

[[Image(http://img651.imageshack.us/i/leakl.png/)]]

http://img651.imageshack.us/i/leakl.png/

I am updating a web interface once per second (stock market ticks) and I am getting a small memory leak over time.

This is causing me a problem for an application designed to be left open on a big screen for upto 24 hours at a time.

In my real code I am hitting 1.5Gb usage in IE after 24hours, from a 32mb start point.

I have put limited code to reproduce below. Any ideas? Perhaps I have made some mistake somewhere causing this, but I have never looked at jQuery so closely before so apologies if I am being silly.

Code to reproduce:

<html>
    <head>
    <script src="/Scripts/jquery.js" type="text/javascript"></script>
    </head>

    <body>
    <h2>Index</h2>
    <script type="text/javascript">
        $(function () {
            reload();
            setInterval(reload,1000);
        });

        function reload() {
            $(".test").remove();
            $("#container").append("<div class='test'>Item</div>");
        }
    </script>

    <div id='container'>
        
    </div>

    </body>
</html>
Attachments (0)
Change History (9)

Changed March 05, 2011 08:32PM UTC by anonymous comment:1

Working on jsFiddle now.

Changed March 05, 2011 08:39PM UTC by adam.king89 comment:2

Changed March 05, 2011 10:07PM UTC by rwaldron comment:3

component: unfiledmanipulation
priority: undecidedhigh
status: newopen

This may not affect your leak issue, but I would recommend not using setInterval(), but instead create your reloading loop with a recursing setTimeout().

Changed March 05, 2011 10:24PM UTC by adam.king89 comment:4

Can confirm changing to setTimeout() doesn't seem to fix the problem.

Curious as to reasoning behind using recursion? I thought I would be best avoiding it in order to keep the stack size down?

AK

Changed March 06, 2011 05:52AM UTC by rwaldron comment:5

setInterval swallows errors that occur inside the interval, so if the code is broken, it will repeat the broken code instead of stopping on the exception

Changed March 14, 2011 11:15PM UTC by olau comment:6

This sounds as if it is related to bug 5285.

Changed March 15, 2011 01:45PM UTC by olau comment:7

What exact version of IE are you on?

The test case in 5285 is very similar, and gives me orphans in sieve too, but when I try it in plain IE 6, 7 and 8 from the IE Collection, there doesn't appear to be a leak. I don't seem to be getting one from your test case on jsFiddle either. So I'm beginning to wonder whether sieve is trustworthy these days.

Sorry for interrupting, but I'm trying to debug a similar problem and it's certainly not easy to pinpoint where the issue is.

Changed March 15, 2011 02:05PM UTC by aking@isatec.co.uk comment:8

Hi,

I have tested across different IE versions. I am away from my desk at the moment but I will update accordingly when I am home.

I have tested using both sIEve and Drip, but I don't know how correct they are, I assumed they were trustworthy but you might have a point in that that might be part of the issue.

I'd not heard of IE Collection until just now, I'll run a few experiments over night using it tonight.

Cheers.

AK

Changed July 12, 2011 04:37PM UTC by rwaldron comment:9

resolution: → worksforme
status: openclosed