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

Memory leak when removing an element. #241

Closed
zhaostu opened this issue May 7, 2014 · 4 comments
Closed

Memory leak when removing an element. #241

zhaostu opened this issue May 7, 2014 · 4 comments

Comments

@zhaostu
Copy link

zhaostu commented May 7, 2014

Doing a code search, I found that all elements created by Snap.svg are stored in a context variable hub:
https://github.com/adobe-webplatform/Snap.svg/blob/master/dist/snap.svg.js#L838

No element are ever removed from hub, even if element.remove() is called. Thus, if a large amount of objects are added and then removed, it will create a really bad memory leak as no element object, or the corresponding detached DOM element is freed from memory.

Also since hub is a context variable created in a closure, I cannot release the object even manually.

Please provide a method on Element object to remove the element from hub object and let GC to collect it.

@zhaostu
Copy link
Author

zhaostu commented May 7, 2014

In order to illustrate this, I created a jsbin http://jsbin.com/bapuxo/2/edit, that if you click "Go", it will leak memory.

DmitryBaranovskiy added a commit that referenced this issue May 8, 2014
@zhaostu
Copy link
Author

zhaostu commented May 8, 2014

@DmitryBaranovskiy Thank you for the fast fix. But I would suggest maybe a element.destory() method could give the user more control (although more coding)? Or element.remove() will always detach the element from hub? Or maybe an option in element.remove(true) to specify the intention that the element will never be used.

Ideas?

@DmitryBaranovskiy
Copy link
Contributor

This would make sense if Snap API was the only way user could interact with the DOM. What if whole <div> that contained SVG element was deleted or div.innerHTML = "";, not to mention direct operation of SVG DOM.

@zhaostu
Copy link
Author

zhaostu commented May 9, 2014

@DmitryBaranovskiy Make sense, thanks.

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

No branches or pull requests

2 participants