Closed Bug 1586495 Opened 5 years ago Closed 4 years ago

Drawing some gradients on <canvas> seems to cause memory leak

Categories

(Core :: Graphics: Canvas2D, defect, P3)

69 Branch
defect

Tracking

()

RESOLVED FIXED
Tracking Status
firefox-esr78 --- wontfix
firefox88 --- wontfix
firefox89 --- fixed
firefox90 --- fixed

People

(Reporter: v910JQK, Unassigned)

References

Details

Attachments

(4 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0

Steps to reproduce:

I'm using Firefox 69.0.1 (x86_64) on Windows10.
The problem happened when I try to create a simple HSL color picker for web development. Open the uploaded sample HTML file, it renders a <canvas> and a 'Draw' button. Click the button many times, you can see the memory used by Firefox grows rapidly.

Actual results:

It seems that drawing a slice plane of the HSL color cylinder on <canvas> could cause memory leak. This problem may have something to do with CanvasRenderingContext2D.createLinearGradient()

Expected results:

Chromium does not have the same problem.

Actually the garbage collector (? or other memory management tech) works when the used memory reaches a big amount. But it is too late. The browser tab may crash before the GC starting to work.

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Canvas: 2D
Product: Firefox → Core

Can you upload the contents of about:support as a text file?

Flags: needinfo?(v910JQK)
Attached file about-support.json
Flags: needinfo?(v910JQK)

Happens in nightly as well, both with webrender and non-webrender.

The memory system seems to clean up, but only after switching away and back to the tab. As far as I can see, memory logs don't show major differences between high and low usage.
Attached memory reports. (Content tab PID=23056)

Priority: -- → P3

Lee, can you take a look?

Flags: needinfo?(lsalzman)

(In reply to Kris Taeleman (:kris/kris) from comment #9)

Lee, can you take a look?

My suspicion is this has to do with gfx/thebes/gfxGradientCache, wherein when we purge the caches all is fine, but otherwise we may be too aggressively caching gradients. It looks like we haven't really evaluated whether the amount of caching there even made sense since this code was written originally by Andreas Gal.

This might actually be a good bug for you to check out if there are any simple tweaks we could make here with the nsExpirationTracker usage, like lowering the timer interval and/or number of generations to see if it found a less obnoxiously memory hungry equilibrium. Would you be willing to dig further?

Flags: needinfo?(lsalzman) → needinfo?(ktaeleman)

Yes, can do! Thanks for the explanation.

Flags: needinfo?(ktaeleman)
Assignee: nobody → ktaeleman
Status: UNCONFIRMED → NEW
Ever confirmed: true
Assignee: ktaeleman → nobody

This probably causes a massive memory issue when using the Falstad circuit simulator: http://falstad.com/circuit/

Particularly bad example: https://tinyurl.com/yh22cd7n

Related issues: #490 #592

Flags: needinfo?(bobowencode)

In the latest Beta (89), I landed a change to limit the number of cached gradients, because of the large amount of memory the related Direct2D objects hold.
If you would be able to retest these issues on Beta that would be great.
https://www.mozilla.org/en-US/firefox/channel/desktop/

Flags: needinfo?(v910JQK)
Flags: needinfo?(j.malec)
Flags: needinfo?(bobowencode)

Beta 89 seems to have fixed the problem, thank you!
Memory runaway in the circuit simulator solved.

Flags: needinfo?(j.malec)

(In reply to Jaroslav Malec from comment #14)

Beta 89 seems to have fixed the problem, thank you!
Memory runaway in the circuit simulator solved.

Thanks for confirming, I'm going to close this as fixed.

Status: NEW → RESOLVED
Closed: 4 years ago
Depends on: 1697344
Resolution: --- → FIXED

At least one reporter confirmed this.

Flags: needinfo?(v910JQK)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: