# which method/tool is best to check memory leak for VTK programs on Ubuntu? vtkDebugLeaks enough? or Valgrind/ASan?

**URL:** https://discourse.vtk.org/t/which-method-tool-is-best-to-check-memory-leak-for-vtk-programs-on-ubuntu-vtkdebugleaks-enough-or-valgrind-asan/12461
**Category:** Support
**Created:** [October 10, 2023, 3:09am UTC](https://discourse.vtk.org/t/which-method-tool-is-best-to-check-memory-leak-for-vtk-programs-on-ubuntu-vtkdebugleaks-enough-or-valgrind-asan/12461 "2023-10-10T03:09:36Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![gpu](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/e47c2d/32.png) [@gpu](https://discourse.vtk.org/u/gpu)
#### Post date: [October 10, 2023, 3:09am UTC](https://discourse.vtk.org/t/which-method-tool-is-best-to-check-memory-leak-for-vtk-programs-on-ubuntu-vtkdebugleaks-enough-or-valgrind-asan/12461/1 "2023-10-10T03:09:36Z")

</div>

which method/tool is best to check memory leak for VTK programs on Ubuntu? vtkDebugLeaks enough? or Valgrind/ASan?  
thanks

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [October 10, 2023, 6:25am UTC](https://discourse.vtk.org/t/which-method-tool-is-best-to-check-memory-leak-for-vtk-programs-on-ubuntu-vtkdebugleaks-enough-or-valgrind-asan/12461/2 "2023-10-10T06:25:45Z")

</div>

VTK\_DEBUG\_LEAKS

> [@New feature: getting a stack trace on leaked objects with VTK\_DEBUG\_LEAKS](https://discourse.vtk.org/t/new-feature-getting-a-stack-trace-on-leaked-objects-with-vtk-debug-leaks/835):
>
> I just merged a [new feature](https://gitlab.kitware.com/vtk/vtk/merge_requests/5448) to VTK that augments vtkDebugLeaks. This feature lets you record a stack trace where leaked VTK objects were allocated. This can be a very useful when debugging VTK object leaks. Previously, if you configured VTK with VTK\_DEBUG\_LEAKS set to ON, VTK would report the types of VTK objects that were never deleted and how many there were when the application exited. This was a useful feature to let you know there was a leak, but it didn’t provide much insight into where t…

---

<div class="post-metadata">

### Author: ![gpu](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/e47c2d/32.png) [@gpu](https://discourse.vtk.org/u/gpu)
#### Post date: [October 10, 2023, 6:42am UTC](https://discourse.vtk.org/t/which-method-tool-is-best-to-check-memory-leak-for-vtk-programs-on-ubuntu-vtkdebugleaks-enough-or-valgrind-asan/12461/3 "2023-10-10T06:42:10Z")

</div>

thanks!  
may i ask it’s added since which version of VTK?  
using it is enough to detect memory leaks, as Valgrind and ASan?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [October 10, 2023, 6:49am UTC](https://discourse.vtk.org/t/which-method-tool-is-best-to-check-memory-leak-for-vtk-programs-on-ubuntu-vtkdebugleaks-enough-or-valgrind-asan/12461/4 "2023-10-10T06:49:09Z")

</div>

VTK\_DEBUG\_LEAKS is old, while the link I shared is only present in VTK 9.

Valgrind and Asan will find more potential leaks but will have a lot of false positive as they rely on monitoring the memory directly (kindof).

VTK \_DEBUG\_LEAKS will find all vtkObject that are not correct deallocated.

---

<div class="post-metadata">

### Author: ![gpu](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/e47c2d/32.png) [@gpu](https://discourse.vtk.org/u/gpu)
#### Post date: [October 10, 2023, 6:56am UTC](https://discourse.vtk.org/t/which-method-tool-is-best-to-check-memory-leak-for-vtk-programs-on-ubuntu-vtkdebugleaks-enough-or-valgrind-asan/12461/5 "2023-10-10T06:56:44Z")

</div>

thanks, also find VTK\_DEBUG\_LEAKS in vtk-8.1, so what’s ur suggestion on Ubuntu? just use VTK\_DEBUG\_LEAKS? or maybe combine it with valgrind or ASan? or just use ASan/valgrind?  
the project has some custom derived class from vtk class

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [October 10, 2023, 11:54am UTC](https://discourse.vtk.org/t/which-method-tool-is-best-to-check-memory-leak-for-vtk-programs-on-ubuntu-vtkdebugleaks-enough-or-valgrind-asan/12461/6 "2023-10-10T11:54:13Z")

</div>

If you have a suspicion for a leak, enable VTK\_DEBUG\_LEAKS, if nothing comes up, use valgrind.

---

<div class="post-metadata">

### Author: ![whereismymoney](https://discourse.vtk.org/user_avatar/discourse.vtk.org/whereismymoney/32/6859_2.png) [@whereismymoney](https://discourse.vtk.org/u/whereismymoney)
#### Post date: [April 2, 2026, 6:21am UTC](https://discourse.vtk.org/t/which-method-tool-is-best-to-check-memory-leak-for-vtk-programs-on-ubuntu-vtkdebugleaks-enough-or-valgrind-asan/12461/7 "2026-04-02T06:21:10Z")

</div>

What is your opinion of these statements from Google AI:

If “top” shows massive memory growth while Valgrind reports very little, you are likely experiencing a “pseudo-leak”—memory that is still technically reachable (and thus not a “leak” to Valgrind) but is growing uncontrollably.  
In VTK applications, this happens for three common reasons:

1. The VTK Pipeline Cache  
VTK filters often cache their output to speed up subsequent updates. If you are running a loop that constantly updates a pipeline with new data, VTK may be holding onto every intermediate result.

2. GPU/Driver “Bloat”  
Memory growth shown in top often includes memory mapped by the OpenGL/Graphics driver. Valgrind cannot see inside the driver or kernel.

3. Container Growth (Still Reachable)  
If you are storing VTK objects (or vtkSmartPointers) in an std::vector or std::map and forgetting to clear it, Valgrind won’t call this a “leak” because you still have a pointer to the memory.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [April 2, 2026, 6:32am UTC](https://discourse.vtk.org/t/which-method-tool-is-best-to-check-memory-leak-for-vtk-programs-on-ubuntu-vtkdebugleaks-enough-or-valgrind-asan/12461/8 "2026-04-02T06:32:04Z")

</div>

> [@whereismymoney](#):
>
> What is your opinion of these statements from Google AI:

No opinion.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [April 2, 2026, 11:27am UTC](https://discourse.vtk.org/t/which-method-tool-is-best-to-check-memory-leak-for-vtk-programs-on-ubuntu-vtkdebugleaks-enough-or-valgrind-asan/12461/9 "2026-04-02T11:27:40Z")

</div>

I used the valgrind heap profile tool `massif` on Ubuntu recently to identify where memory was being allocated and not freed when it should have been, though it was freed by program shutdown. Hence it was not technically a leak that VTK\_DEBUG\_LEAKS or valgrind by itself would show. See docs for it at [Valgrind](https://valgrind.org/docs/manual/ms-manual.html)

---

<div class="post-metadata">

### Author: ![whereismymoney](https://discourse.vtk.org/user_avatar/discourse.vtk.org/whereismymoney/32/6859_2.png) [@whereismymoney](https://discourse.vtk.org/u/whereismymoney)
#### Post date: [April 2, 2026, 7:39pm UTC](https://discourse.vtk.org/t/which-method-tool-is-best-to-check-memory-leak-for-vtk-programs-on-ubuntu-vtkdebugleaks-enough-or-valgrind-asan/12461/10 "2026-04-02T19:39:56Z")

</div>

If I put this

```cpp
#include <vtkDataObject.h>

// Call this early in your main()
vtkDataObject::GlobalReleaseDataFlagOn();

```

at the beginning of my program, it will still work but just be less efficient, is that right?

I have about 100 GB of RAM full of stuff that is either due to a leak or a pseudo-leak. Is there some way to switch on some VTK verbosity so that if I look at a memory dump I can figure out what these objects are? I suspect they are vtkPolyData or related things, but something like a vtkDoubleArray probably has little or no header by default, when looking at a memory dump.
