adobe-webplatform / Snap.svg

The JavaScript library for modern SVG graphics.
http://snapsvg.io
Apache License 2.0
13.91k stars 1.15k forks source link

Memory leak when there are SVG elements with foreignObject elements #656

Open eturpin opened 2 years ago

eturpin commented 2 years ago

There seems to be a memory leak that occurs when SVG elements are nested inside foreignObject elements. A "garbage collector" was created to fix #241, but I don't think SVG elements within foreignObject elements will ever be removed from the hub object. foreignObjects will not have a ownerSVGElement property defined, so the delete hub[key]; line will never be executed in the garbage collector.

Would replacing this line in the garbage collector:

if (el.type != "svg" && !node.ownerSVGElement || el.type == "svg" && (!node.parentNode || "ownerSVGElement" in node.parentNode && !node.ownerSVGElement))

with

if (!node.isConnected)

be a suitable solution?