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

dispose should clear activeInstance #2701

Closed
codepunkt opened this issue Dec 21, 2015 · 9 comments · Fixed by #2708
Closed

dispose should clear activeInstance #2701

codepunkt opened this issue Dec 21, 2015 · 9 comments · Fixed by #2708
Labels

Comments

@codepunkt
Copy link

If it doesn't (current state), the last instance is always leaked even after disposed and removed.

@asturur
Copy link
Member

asturur commented Dec 22, 2015

You mean something like this?

    /**
     * Clears a canvas element and removes all event listeners
     * @return {fabric.Canvas} thisArg
     * @chainable
     */
    dispose: function () {
      this.clear();
      this.interactive && this.removeListeners();
      if (fabric.Canvas.activeInstance === this) {
        fabric.Canvas.activeInstance = null;
      }
      return this;
    },

@codepunkt
Copy link
Author

Exactly.

@asturur
Copy link
Member

asturur commented Dec 23, 2015

i do not really know the use of tha activeInstance property. track the canvas variable and clean it? and in case of multiple canvases?

@kangax kangax added the bug label Dec 24, 2015
@kangax
Copy link
Member

kangax commented Dec 24, 2015

I agree that we should be clearing it

@asturur
Copy link
Member

asturur commented Dec 24, 2015

this is a fast pr.

@asturur
Copy link
Member

asturur commented Dec 24, 2015

proposed this in a PR in dispose method:

+      var klass = fabric[fabric.util.string.capitalize(this.type)];
+      if (klass.activeInstance === this) {
+        klass.activeInstance = null;
+      }

@kangax
Copy link
Member

kangax commented Dec 24, 2015

@gonsfx out of curiosity, how are you using activeInstance and would you be OK if we removed it entirely (as it seems to belong on an application level)?

@codepunkt
Copy link
Author

@kangax I'm not using it at all, just found out that it can lead to leaks.

@asturur
Copy link
Member

asturur commented Dec 26, 2015

on #2708 we are deleting it.

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

Successfully merging a pull request may close this issue.

3 participants