Open cjgammon opened 9 years ago
Also clean up maskGroups when emptied.
To achieve this we should have a pool of items that are link dependent, then upon RemoveCommand, we should also remove these from that pool and check if the item that is dependent upon them has any other dependencies, if not, remove it as well.
Added GarbagePool class, need to confirm removing defs like gradients and masks.
Am having issues w/ DOM slowdown when dynamically changing animations (injecting/changing them in the dom) is this related?
Do you have an example file I can look at? Depending on what's being manipulated and how, as well as how many, it could be any number of things.
@cjgammon I'm using React to load animation/hero components based on params. Behind the scenes it's using pushes to react router's history to navigate programmatically - then it sets the namespaced var pns.anim = null
and runs delete pns.anim
(a step I added later in investigations to see if it improved). Here's a gist of the code behind the three pieces of code that are in the immediate area of concern - https://gist.github.com/reidblomquist/255f277ca0ceac767e4282b769c5a402 ; the animations themselves and some of the content is under NDA so I can't put a full example together with them, but if you have some sample SVGAnimator anims I could use I could whip up a full example repo, or can throw together some sample anims myself.
I see what you're trying to do. If you could send an example that I can try to debug that would be more helpful. It may very well be a memory issue around either certain objects or DOM elements not being cleaned up properly.
I had a similar issue, with a similar setup: a list of anims that are rendered on the same container along the life of the application depending on the params received by the app. Sometimes one by second, other times, on every 30 secs. During an event I can get around 600 messages that need to be "animated".
My first attempts were leaking memory so I changed my approach:
I have only one instance of SVGAnim since all animations are rendered in the same
Then I added a clear() method:
this.clear = function () {
instance.s.clear();
playing = false;
};
That way Snap removes everything in my
This solved most of the leaks (Snap.svg has its own memory leaks) and improved the performance.
This, and updating eve to version 0.5.0 (also mentioned on that thread), helped to fix Snap.svg memory leaks:
https://github.com/adobe-webplatform/Snap.svg/issues/369
Hope this helps.
Manage defs, cleanup when unused.