Skip to content

Potential risk of memory leaks #19

@kimikage

Description

@kimikage

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,

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');

and the event handlers refers them.
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions