Page MenuHomePhabricator

Memory leak when updating 2D images
Closed, ResolvedPublic

Description

When updating the 2D rendering memory usage increases -> memory leak.

Can be reproduced by:

  1. Load arbitrary image
  2. Clicking in 2D render window and moving the mouse

Leak only occurs on Windows. Could neither be reproduced on Linux nor on Mac.

Event Timeline

We figured this also occurs if just a point set loaded. As a consequence, the image rendering is not involved.

TODO: Test if this occurs if the SliceNavigationController is used to update the rendering process.

Due to its severity, this bug is considered relevant for the upcoming 2012.09 release.

Please check the status and consider fixing this bug for 2012.09.

I searched for "new " in the source code to find potentially leaking code and found a lot of leaks in the interactors as well as other classes.

Since I do not have the rights to create a wiki page, here is the bug description:

Moving the mouse in the 2D windows constantly increases memory usage. This is mainly due to allocated memory for point operations in interactors which are not released in case the interactor doesn't support undo.

Additionally I removed some unnecessary heap allocations for point operations which are solely allocated for a following call after which they are deallocated again. I put them on the stack instead.

This fix touches the following files:

mitkSliceNavigationController.cpp
mitkSlicesRotator.cpp
mitkSlicesSwiveller.cpp
mitkPointSet.cpp
mitkAffineInteractor.cpp
mitkCoordinateSupplier.cpp
mitkDisplayVectorInteractor.cpp
mitkInteractor.cpp
mitkMoveSurfaceInteractor.cpp
mitkPointSetInteractor.cpp

Another big memory leak occurs in mitkPlanePositionManager.cpp which holds a container of pointers which are not deleted when the items are erased from the container.

Finally i fixed a missing "delete" in usServiceTrackerTest.cpp by replacing the pointer by a scope aware pointer.

One hint: instead of searching for "new" or "delete", you could use valgrind, which will point to to the exact lines and reasons for leaks.

This touches a lot of core classes.

While it is great that these leaks are fixed, I would like to have a quick look through the changes before merging them so shortly before the final release. Can you publish a branch?

I already pushed the branch: origin/bug-10180-MemoryLeakWhenUpdating2DImages. :)

Changed component and added party flag. Can you push this asap?

[02042d]: Merge branch 'bug-10180-MemoryLeakWhenUpdating2DImages'

Merged commits:

2012-09-12 13:56:00 Stefan Kislinskiy [a64c07]
Fixed numerous memory leaks in the core.

[326c11]: Merge branch 'bug-10180-AutoPtrFix'

Merged commits:

2012-09-26 11:51:51 Stefan Kislinskiy [667455]
COMP: Added missing inclusion of std memory header.