Bug Tracker

Modify

Ticket #8450 (closed bug: worksforme)

Opened 3 years ago

Last modified 3 years ago

Memory Leak when removing objects (leaving orphans)

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

Description

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

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>

Change History

comment:1 Changed 3 years ago by anonymous

Working on jsFiddle now.

comment:2 Changed 3 years ago by adam.king89

comment:3 Changed 3 years ago by rwaldron

  • Priority changed from undecided to high
  • Status changed from new to open
  • Component changed from unfiled to manipulation

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

comment:4 Changed 3 years ago by adam.king89

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

comment:5 Changed 3 years ago by rwaldron

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

comment:6 Changed 3 years ago by olau

This sounds as if it is related to bug 5285.

comment:7 Changed 3 years ago by olau

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.

comment:8 Changed 3 years ago by aking@…

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

comment:9 Changed 3 years ago by rwaldron

  • Status changed from open to closed
  • Resolution set to worksforme

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.