Closed
Bug 939510
Opened 12 years ago
Closed 12 years ago
revokeObjectURL() does not free up memory if the BLOB URL was served as a download
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
FIXED
mozilla28
People
(Reporter: bk, Assigned: bzbarsky)
References
Details
Attachments
(2 files)
470 bytes,
text/html
|
Details | |
4.95 KB,
patch
|
jduell.mcbugs
:
review+
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.14 Safari/537.36
Steps to reproduce:
1. Create a BLOB with binary data.
2. Create a BLOB URL with window.URL.createObjectURL()
3. Serve the binary data as a file download (by using the "download" attribute in the <a> element to define the filename).
4. Use window.URL.revokeObjectURL() to clear the BLOB from memory.
Actual results:
Memory does not get cleared. Suspect that the running download creates another reference to the BLOB that never gets cleared so that the BLOB never gets garage collected. This is a relatively new feature, as support for the "download" attribute in the <a> element was only added to Firefox 20.
For a proof of concept see the attached file: firefoxleak.html
The bug also occurs when calling window.URL.revokeObjectURL() _after_ the download has completed, so it cannot be worked around.
Expected results:
Upon download completion there should not be any reference to the BLOB any longer, allowing the garbage collector to free up the memory.
Updated•12 years ago
|
Component: Untriaged → DOM
Product: Firefox → Core
Summary: MEMORY LEAK: revokeObjectURL() does not free up memory if the BLOB URL was served as a download → revokeObjectURL() does not free up memory if the BLOB URL was served as a download
![]() |
Assignee | |
Comment 1•12 years ago
|
||
Does this only happen when downloading? So if you load a blob in an iframe, for example, the problem doesn't occur?
Flags: needinfo?(khuey)
Reporter | ||
Comment 2•12 years ago
|
||
(In reply to Boris Zbarsky [:bz] from comment #1)
> Does this only happen when downloading? So if you load a blob in an iframe,
> for example, the problem doesn't occur?
What exactly do you mean with "load a BLOB in an iframe"? Our goal is to serve binary data as file download to the user (the files are not pre-viewable in the browser).
To find out whether this memory leak also applies in other situations (e.g. with rendering content inside the browser), I would suggest the following approach:
1. Create BLOB URL's for various images.
2. Render them to the DOM
3. Remove them from the DOM.
4. Use window.URL.revokeObjectURL() and see if the data stays in memory.
This would however be different from the issue described above, so it would be a separate (related) issue.
![]() |
Assignee | |
Comment 3•12 years ago
|
||
The question is whether this is an issue in blob code or in download code.
Reporter | ||
Comment 4•12 years ago
|
||
(In reply to Boris Zbarsky [:bz] from comment #3)
> The question is whether this is an issue in blob code or in download code.
Probably in the download code? When the BLOB URL is passed as a download does it create another reference to the BLOB? It should probably free that reference when:
a) the user cancels the download
b) the download completes
![]() |
Assignee | |
Comment 5•12 years ago
|
||
There is nothing blob-specific in the download code. Which is why I think we should check whether this in fact only happens with downloads.
Reporter | ||
Comment 6•12 years ago
|
||
I think the fact that there is nothing blob-specific in the download code is exactly the problem. Shouldn't a blob-download free the reference upon completion? (note that a blob download can take several minutes when it's a large file)
It only seems to happen with downloads. I tested the loading of blob url's in the browser (by passing them to a img.src) and in this case everything works as expected (e.g. no memory leak):
var url = function()
{
var a = URL.createObjectURL(new Blob([Array(1000001).join('x')]));
(new Image()).src = a;
setTimeout(function(a)
{
console.log(a);
URL.revokeObjectURL(a);
url();
},500,a);
}
url();
![]() |
Assignee | |
Comment 7•12 years ago
|
||
> Shouldn't a blob-download free the reference upon completion?
Not any more so than any other load of the data, I would think.
Reporter | ||
Comment 8•12 years ago
|
||
Here is another example that does work correctly. According to my tests blob url downloads cause the handle leak, while other uses of the blob url don't.
<iframe id="fr"></iframe>
<script type="text/javascript">
var url = function()
{
var a = URL.createObjectURL(new Blob([Array(1000001).join('x')]));
document.getElementById('fr').src=a;
setTimeout(function(a)
{
console.log(a);
URL.revokeObjectURL(a);
url();
},500,a);
}
url();
</script>
![]() |
Assignee | |
Comment 9•12 years ago
|
||
So there are two things going on here:
1) Something in the Firefox UI (the download manager?) is keeping the nsIChannel alive for
the download.
2) An nsInputStreamChannel never nulls out its mContentStream, even after OnStopRequest.
I think we should fix #2, which would drop the data in this case. Jason?
I also think we should file a separate bug on #1, because that just seems fishy....
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(jduell.mcbugs)
Flags: needinfo?(gavin.sharp)
Updated•12 years ago
|
Flags: needinfo?(gavin.sharp) → needinfo?(paolo.mozmail)
Comment 10•12 years ago
|
||
(In reply to Boris Zbarsky [:bz] from comment #9)
> I also think we should file a separate bug on #1, because that just seems
> fishy....
Filed bug 941726 with a patch that indirectly fixes this leak. We should probably fix cause #2 as well.
Flags: needinfo?(paolo.mozmail)
Comment 11•12 years ago
|
||
> 2) An nsInputStreamChannel never nulls out its mContentStream, even after OnStopRequest.
>
> I think we should fix #2, which would drop the data in this case. Jason?
That looks like a sensible approach to me.
Flags: needinfo?(jduell.mcbugs)
![]() |
Assignee | |
Comment 12•12 years ago
|
||
Attachment #8338790 -
Flags: review?(jduell.mcbugs)
![]() |
Assignee | |
Updated•12 years ago
|
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
![]() |
Assignee | |
Updated•12 years ago
|
Flags: needinfo?(khuey)
Whiteboard: [need review]
Updated•12 years ago
|
Attachment #8338790 -
Flags: review?(jduell.mcbugs) → review+
![]() |
Assignee | |
Comment 13•12 years ago
|
||
Flags: in-testsuite?
Whiteboard: [need review]
Target Milestone: --- → mozilla28
Comment 14•12 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•