various memory leaks involving listeners and XHRs

RESOLVED WORKSFORME

Status

()

Core
General
RESOLVED WORKSFORME
6 years ago
6 years ago

People

(Reporter: peter.pisljar, Assigned: khuey)

Tracking

9 Branch
x86_64
Windows 7
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [MemShrink:P2])

Attachments

(2 attachments)

(Reporter)

Description

6 years ago
Created attachment 586009 [details]
leaktest.zip

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7

Steps to reproduce:

I am trying to use eventsource in my web application. For older version of browsers
i want to implement same functionality using xmlhttprequest.

eventsource:

- i create request source
- i add listener to it
- in listener i output recieved data


xmlhttprequest:
- i create xmlhttprequest
- i **** onreadystatechange event
- open and send request
- in onreadystatechange event i check if i got some data already
- if its true i do something with data

sync method:
- setinterval(myfunction, 50), then inside myfunction:
- i create xmlhttprequest
- send, open, do something with data
- set xmlhttprequest to null


Actual results:

in all of the above described methods i get HUGE memory leaks. In provided
file i included all the examples (open index.php) there are two examples using eventsource, one is getting data at rate 20 per second (open stream.php to change it)
the other is getting data as fast as possible (streamfast.php).
there are two examples using xmlhttprequest (slow and fast) and one example
using sync xmlhttprequests (20 per second).

i tried running examples in all mayor firefox versions from 3 to 9 and i get similar
results in all of them.

when using fast examples sometimes memory jumps from 100MB to 2GB in just
5 seconds (and i'm not actualy recieving that much data)

with slow examples its sometimes harder to see how memory is growing, but if you
leave it open for some time you will see it. sometimes even with datarates as low as
10kb/s my memory is growing for 1MB/s


Expected results:

well, there should be no memory leak :) i dont know if i am doing something wrong
or firefox actualy has such problems (in chrome all examples work much better)

if there is a simple fix i would ask for some tips, else i hope you fix this soon :)
its not a problem with webpage which does a few requests, but when making
app which should work for few hours its a big problem as firefox crashes a LOT.

thank you
Attachment #586009 - Attachment mime type: text/plain → application/zip
I can't test this (no PHP), maybe someone else can test and compare this testcase with other browsers ?
Component: Untriaged → General
Product: Firefox → Core
QA Contact: untriaged → general
Whiteboard: [memshrink]
Comment on attachment 586009 [details]
leaktest.zip

I just had a quick look over these tests and they need a few changes so they work correctly. They have problems like missing jQuery causing error, executing before body has loaded, etc.

I also suggest removing jQuery completely since it does not seem to be used as an important part of the tests and may effect the results.
(Reporter)

Comment 3

6 years ago
sorry for problematic test cases. first i did it without jquery, then i added jquery
to see if it would work better, however it didnt, so i wanted to remove jquery
before posting it here .... hoever it seems i did a lauzy job.

but even then i guess you can see the idea behind test cases (test1.php is nothing ...)
(In reply to peter.pisljar from comment #3)
> sorry for problematic test cases. first i did it without jquery, then i
> added jquery
> to see if it would work better, however it didnt, so i wanted to remove
> jquery
> before posting it here .... hoever it seems i did a lauzy job.
> 
> but even then i guess you can see the idea behind test cases (test1.php is
> nothing ...)

Can you please update the tests to fix them?  It'll be hard to make any progress here without working tests.
Summary: various memory leaks → various memory leaks involving listeners and XHRs
If I had to guess what's going on here, we have a bunch of XHRs that are holding on to lots of native memory, but the growth in the gc heap is small enough that we don't trigger the gc that would collect them.

A working testcase would help a lot though.
(Reporter)

Comment 6

6 years ago
i will provide you with working test cases later today.
(Reporter)

Comment 7

6 years ago
Created attachment 587773 [details]
updated test cases ....
Attachment #587773 - Attachment mime type: text/plain → application/zip
Whiteboard: [memshrink] → [MemShrink:P2]
khuey, want to take a look?

I tried to reproduce but the test is mostly PHP files, do you need a PHP server going?  I don't have that.

peter, if you go into about:memory and hit "minimize memory usage" does the excessive use drop?  If so, then khuey's hypothesis in comment 5 is probably correct.
I could take a look, but I'm at a work week now, and then I have to move across the US, so it's like to be a while before I can really dig in here.

If somebody can put the testcases on the web somewhere and verify that the leak is reproducible I can probably fit investigating that in soon.

Comment 10

6 years ago
(In reply to Kyle Huey [:khuey] (khuey@mozilla.com) from comment #9)
> If somebody can put the testcases on the web somewhere and verify that the
> leak is reproducible I can probably fit investigating that in soon.

http://junglecode.com/sites/715451/
Assignee: nobody → khuey
I don't see any jumps anywhere near 2 GB (most I saw was 250 MB) and when the garbage collector runs we reclaim the memory.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.