Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly dispose of canvas resources on graphics.destroy() #537

Open
fjwong opened this issue Feb 26, 2021 · 1 comment
Open

Properly dispose of canvas resources on graphics.destroy() #537

fjwong opened this issue Feb 26, 2021 · 1 comment
Labels

Comments

@fjwong
Copy link

fjwong commented Feb 26, 2021

Apologies in advance if work towards addressing this is already in progress, and also thank you for the effort you've poured into this library.

I had originally submited a PR for this (#495) but it seems to have been closed due to inactivity.

The recently released v3.12.0 seems to not include this fix yet, so I'm opening this issue in the hopes this helps it to be resolved quickly.

The issue:

When calling imageEditor.destroy() (which also calls graphics.destroy() under the hood), memory resources are not entirely freed up, causing eventual out of memory errors if multiple image editor instances are created, and subsequently destroyed (like when opening/closing a popup window that contains an image editor instance).

The out of memory errors are more easily reproducible on mobile devices.

The (potential) fix:

I traced the error to graphics.js' destroy method which seems to be calling Fabric.js' canvas.clear() method (which clears canvas properties and objects in it) instead of canvas.dispose().

Although I haven't examined them in deep, I believe this may be related to issues #208, #213, #375, #395, #488 and similar out of memory issues that have been reported in the past.

A workaround:

People experiencing this can potentially address this by explicitly calling canvas.dispose() when destroying an image editor instance:

// When destroying the image editor instance...
const imageEditor  = ... // Image editor instance
const canvas = imageEditor._graphics._canvas; // Get reference to fabric.Canvas object
imageEditor.destroy(); // Destroy the image editor instance
canvas.dispose(); // Finish disposing canvas resources
@fjwong fjwong added the Bug label Feb 26, 2021
@lja1018
Copy link
Contributor

lja1018 commented Mar 3, 2021

@fjwong
Sorry for the closing of the PR. It will be released in v3.13.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants