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

can't identify what's causing memory leak #188

Closed
IbrahimCSAE opened this issue Aug 25, 2022 · 5 comments
Closed

can't identify what's causing memory leak #188

IbrahimCSAE opened this issue Aug 25, 2022 · 5 comments

Comments

@IbrahimCSAE
Copy link
Collaborator

IbrahimCSAE commented Aug 25, 2022

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

Screenshot_5
Screenshot_6
Screenshot_7

@sedghi
Copy link
Member

sedghi commented Aug 25, 2022

There is a destory exported for CornerstoneTools3D, use that

@IbrahimCSAE
Copy link
Collaborator Author

There is a destory exported 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.

@IbrahimCSAE
Copy link
Collaborator Author

IbrahimCSAE commented Aug 25, 2022

    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?

@sedghi
Copy link
Member

sedghi commented Aug 31, 2022

Yes it seems like there is a leak. the load just start the loading, createAndCacheVolume does not load the images in yet

@sedghi
Copy link
Member

sedghi commented Oct 13, 2023

This might be related

OHIF/Viewers#3207

@sedghi sedghi closed this as completed Oct 13, 2023
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