cornerstone3D
cornerstone3D copied to clipboard
can't identify what's causing memory leak
Hello,
I'm using cornerstone3D for a project I'm working on, and I have a viewer component that uses it, I'm trying to clear memory when I unmount the component, here's the unmount function I use:
unmounted() {
// delete tool group
cornerstone3DTools.ToolGroupManager.destroyToolGroup(this.toolGroupId);
// remove Tools
cornerstone3DTools.removeTool(cornerstone3DTools.WindowLevelTool);
cornerstone3DTools.removeTool(cornerstone3DTools.PanTool);
cornerstone3DTools.removeTool(cornerstone3DTools.ZoomTool);
cornerstone3DTools.removeTool(cornerstone3DTools.StackScrollMouseWheelTool);
cornerstone3DTools.removeTool(cornerstone3DTools.CrosshairsTool);
// purge cache
cornerstone3D.cache.purgeCache();
// destory render engine
this.renderingEngine.destroy();
// register regular cornerstone to the image loader again
cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
},
However, even with this function running when the component is unmounted, there's massive memory leak. Is there something I'm missing? am I not clearing memory the right way? if there's a function I should call that I'm not, please point that out to me as I can't figure out what to do.
I'm using old cornerstone in other components, and the cornerstone.imageCache.purgeCache(); does the job there, I don't know why it's not doing it's job in cornerstone3D

There is a destory exported for CornerstoneTools3D, use that
There is a
destoryexported for CornerstoneTools3D, use that
It still doesn't fix the huge leaks happening, I think it's from Cornerstone3D itself, not the tools.
The leaks are usually huge like 400MB+ , and If I keep mounting and unmounting the component the leaks keep getting bigger and bigger until it crashes.
createVolume: async function (series) {
let volumeName = series.seriesInstanceUID;
let volumeLoaderScheme = "cornerstoneStreamingImageVolume";
let volumeId = `${volumeLoaderScheme}:${volumeName}`;
this.volumeId = volumeId;
const ctVolume = await cornerstone3D.volumeLoader.createAndCacheVolume(
volumeId,
{ imageIds: series.imageIds }
);
return // i returned here and the memory problem doesn't happen anymore
// load the volume
ctVolume.load();
},
it seems to me that ctVolume.load() is what causes the problem, whatever resources that allocates, don't seem to get cleaned up.
Is there something like ctVolume.unload() that I can use? if not then how do I go about clearing this manually?
Yes it seems like there is a leak. the load just start the loading, createAndCacheVolume does not load the images in yet
This might be related
https://github.com/OHIF/Viewers/issues/3207