View Issue Details

IDProjectCategoryView StatusLast Update
0003283Slicer4Module Editorpublic2014-03-06 06:15
Reporterlassoan Assigned Topieper  
PrioritynormalSeveritycrashReproducibilityalways
Status closedResolutionfixed 
Product Version 
Target VersionSlicer 4.4.0Fixed in VersionSlicer 4.4.0 
Summary0003283: Crash in editor due to out of memory
Description

There is a huge memory leak in the Editor module that causes crash in a few clicks (depending on the volume size and available memory), using any editor effect.

How to reproduce:

  • Download CTChest sample
  • Go to Editor module
  • Choose the PaintEffect
  • Click on the image multiple times => approximately 70MB memory is leaked at each click, until Slicer finally crashes

On my computer with the CTChest sample you have to click 57 times (which is a quite low number when a full volume is segmented manually), with the CTACardio the crash occurs after 25 clicks, and on a high-resolution CT it happens after 12 clicks.

Slicer 4.2.0-2013-08-07 (Win64), on Win7, 8GB RAM

TagsNo tags attached.

Relationships

has duplicate 0003619 closedpieper Runtime error when trying to use wand tool 

Activities

lassoan

lassoan

2013-08-09 21:42

developer   ~0009454

From: Steve Pieper [mailto:pieper@ibility.net]
Sent: August 10, 2013 12:58 AM
To: Andras Lasso
Cc: Ors Petnehazy
Subject: Re: Editor crash due to memory leak

Yes, it must be something like that. If we rule out the editor's undo buffer we can look at other things.

The easiest thing is probably to override the Register and UnRegister virtual methods in vtkImageData and set breakpoints to see where the reference count is being incremented but not decremented.

-Steve

On Fri, Aug 9, 2013 at 6:52 PM, Andras Lasso <lasso@cs.queensu.ca> wrote:
Even with a medium resolution CT as CTChest, each click leaks 72MB.
The compressed labelmap is just 71KB. The CTChest volume size is 145MB uncompressed, 42MB compressed.

Maybe the input volume is saved in the undo buffer as well (because something marks it as modified)?

Andras

From: Steve Pieper [mailto:pieper@ibility.net]
Sent: August 10, 2013 12:39 AM

To: Andras Lasso
Cc: Ors Petnehazy
Subject: Re: Editor crash due to memory leak

No, the undo data is compressed. But there might be something else going on which is why I suggested you test it.

-Steve

On Fri, Aug 9, 2013 at 6:37 PM, Andras Lasso <lasso@cs.queensu.ca> wrote:
If the undoSize controls how many complete, uncompressed copies of the volume is kept in memory, then 100 is definitely too much. Even 10 is quite heavy, but should be OK on most 64-bit systems, if the volume is not too big. Please set the default back to 10 until you make it configurable (or you make the undo buffer more memory-efficient).

thanks
Andras

From: Steve Pieper [mailto:pieper@ibility.net]
Sent: August 10, 2013 12:30 AM
To: Andras Lasso
Cc: Ors Petnehazy
Subject: Re: Editor crash due to memory leak

Hi Andras -

No problem - will look into it. It's probably the undoSize option [1]. It used to be 10 but then I upped it to 100 at the request of some users. You might try changing it if you have a chance. If that turns out to be the issue we should make it configurable.

[1] https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/EditorLib/EditUtil.py#L231

Best,
Steve

lassoan

lassoan

2013-08-09 21:43

developer   ~0009455

undoSize set to 5 => the problem is resolved, total amount of leaks is limited

self.undoRedo.saveState() is commented out => the problem is resolved, no leaks at all

So, the problem seems to be in the undo/redo buffer.

lassoan

lassoan

2013-08-09 22:08

developer   ~0009456

Root cause of the problem found: the image stash compresses the buffer but then the buffer is not squeezed (it left at the default size, which is about the same size as the input uncompressed buffer).

Solution:

Replace these lines in vtkImageStash::Stash()

this->SetStashedScalars(this->GetCompressor()->Compress(p, scalarSize));
this->GetStashedScalars()->Delete(); // reference count already set by Compress

by these:

vtkUnsignedCharArray* compressedBuffer=this->GetCompressor()->Compress(p, scalarSize); // returns a new buffer that has to be deleted
compressedBuffer->Squeeze();
this->SetStashedScalars(compressedBuffer);
compressedBuffer->Delete();

Steve, please review and if you agree then commit.

lassoan

lassoan

2013-08-09 22:08

developer   ~0009457

There is one remaining issue: if the user clicks too quickly then Slicer may run out of memory due to the many stashing going on in processing threads.

I've added a new bug report for this issue: http://www.na-mic.org/Bug/view.php?id=3286

lassoan

lassoan

2013-08-13 08:09

developer   ~0009467

Fix committed in rev 22284 (http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=22284).

jcfr

jcfr

2014-03-06 05:21

administrator   ~0011164

Closing resolved issues that have not been updated in more than 3 months

Issue History

Date Modified Username Field Change
2013-08-09 13:12 lassoan New Issue
2013-08-09 13:12 lassoan Status new => assigned
2013-08-09 13:12 lassoan Assigned To => pieper
2013-08-09 13:26 lassoan Description Updated
2013-08-09 21:42 lassoan Note Added: 0009454
2013-08-09 21:43 lassoan Note Added: 0009455
2013-08-09 22:08 lassoan Note Added: 0009456
2013-08-09 22:08 lassoan Note Added: 0009457
2013-08-13 08:09 lassoan Note Added: 0009467
2013-08-13 08:09 lassoan Status assigned => resolved
2013-08-13 08:09 lassoan Resolution open => fixed
2014-03-06 05:21 jcfr Note Added: 0011164
2014-03-06 05:23 jcfr Status resolved => closed
2014-03-06 05:54 jcfr Fixed in Version => Slicer 4.4.0
2014-03-06 06:15 jcfr Target Version => Slicer 4.4.0
2014-04-01 03:40 pieper Relationship added has duplicate 0003619