-
Notifications
You must be signed in to change notification settings - Fork 7
Description
When using ProfileSVG on Jupyter etc., you can remove <SVG> from the DOM tree by clearing the output cell. But the event handlers may not be collected by the GC. Alternatively, the event handlers may prevent some parts of the <SVG> from being collected by the GC.
This is an essential problem, and it is difficult to solve the problem fundamentally, but I think we can reduce the effects of memory leaks.
The current implementation stores the references to <rect> and <text> nodes in fig,
ProfileSVG.jl/src/svgwriter.jl
Lines 55 to 63 in 8ea09a8
| var fig = {}; | |
| fig.viewport = Snap.select('#$fig_id-viewport'); | |
| fig.frame = Snap.select('#$fig_id-frame'); | |
| fig.viewport_cx = fig.viewport.getBBox().cx; | |
| fig.rects = Snap.selectAll('#$fig_id-viewport rect'); | |
| fig.texts = Snap.selectAll('#$fig_id-viewport text'); |
ProfileSVG.jl/src/svgwriter.jl
Lines 74 to 98 in 8ea09a8
| fig.rects.forEach(function(rect, i){ | |
| rect.dblclick(function(){ | |
| bbox = rect.getBBox(); | |
| ProfileSVG.move_and_zoom(bbox.cx, bbox.cx, fig.clip_width/bbox.w, fig); | |
| }) | |
| .mouseover(function(){ | |
| fig.details.nodeValue = rect.node.getAttribute("data-info"); | |
| }) | |
| .mouseout(function(){ | |
| fig.details.nodeValue = ""; | |
| }); | |
| }) | |
| fig.texts.forEach(function(text, i){ | |
| text.dblclick(function(){ | |
| bbox = fig.rects[i].getBBox(); | |
| ProfileSVG.move_and_zoom(bbox.cx, bbox.cx, fig.clip_width/bbox.w, fig); | |
| }) | |
| .mouseover(function(){ | |
| fig.details.nodeValue = fig.rects[i].node.getAttribute("data-info"); | |
| }) | |
| .mouseout(function(){ | |
| fig.details.nodeValue = ""; | |
| }); | |
| }) |
The current implementation should work, but there may be memory issues.
Edit:
The issue of holding the references to nodes was slightly improved in PR #26. However, the memory leaks will not be fixed unless we remove all unnecessary references.