VTK debug leaks with Visual studio 2013


I have observed some strange behavior with “VTK debug leaks” in VS 2013.
In a sample project made with VTK 8.1, I’m able to get the debug leaks in console when I close the application. But in Main project, unable to get the debug leaks on application close.

for clear reasons, couldn’t post the details of classes or code snippets used in main project.

Please let me know if there exist any settings in Visual studio or vtk classes which can block debug info.

Thanks in Advance,

You can turn off leak detection via the VTK_DEBUG_LEAKS=OFF CMake variable. It won’t fix the leaks, but it will make them quiet :slight_smile: .

@ben.boeckel Thank you for the reply.
Actually I wanted to do the opposite of it.

Somehow even with debug leaks on, I’m not getting the leaks in console in vs 2013 when application is closed.

So I’m asking is there any settings which can block the leaks, so I can unblock them and get debug leaks.

Hmm. Maybe there’s a language barrier. What do you mean by “block the leaks”? The only way to fix the leaks is to properly release memory by making sure ::New() calls are paired with ->Delete() calls. You’ll probably have a better time moving to vtkSmartPointer or vtkNew depending on the usage pattern though.

Yes. Sorry for not explaining properly.

Let me put it this way.

I wanted to know about the memory leaks in my application.

I for one know from experience know that if we build the library with debug leaks flag on, we can get the memory leaks present when application is closed.

Earlier I used to work in Linux environment and this process was working great.

But now as I switched to windows using visual studio to build the application and run code using visual studio. I’m facing this issue that when the close the application, I couldn’t get the debug leaks printed.

When I run the application as a console application, using a small project I’m able to get the magic statement… “vtk. has no debug leaks!” .it’s good till this.

But when I try to run my entire project. " which is contributed by many developers like me", the debug leaks are not printed on closing the application and not even the statement that no leaks are there.

So I was wondering if there is any problem with the way visual studio is configured for this particular project or any vtk functions/classes /parameters are blocking this debug leaks to print when application is closed.

So I’m back to this forum to know if there are any such methods/classes which in fact is mistakenly used and there by resulting in hiding the memory leaks.

Please help!

Hope I explained clearly this time.

Thanks in advance…

So other people have been working on the same project? They might have done something that causes the debug output to be hidden. I suggest the following:

  1. Search the code for vtkOutputWindow. Maybe someone used vtkOutputWindow::SetInstance() to redirect the output to a file, or maybe they turned the output off completely.
  2. Also search the code for vtkLogger, for the same reason. Maybe someone is redirecting or hiding the messages.
  3. As a test, call vtkGenericWarningMacro("HELLO!\\n") when the program starts, and check if this warning is printed.

Also, is this project configured with cmake, or is it configured completely within visual studio? Is it configured as a console application?

Hi David,

It’s good to get reply from you. Thank you.

I have spend some time on the code earlier and have quickly checked now too.

  1. vtkOutputWindow is been used, but not able to get the debug leaks with and without this redirection to a file option too.
  2. Regarding vtkLogger, Its not been used.
  3. vtkGenericWarningMacro(“HELLO!\n”), gives an output by popping a window titled [vtkOutputWindow] is the output is not redirected to file. It displays the same output in a file if vtkOutputWindow is used.

This project is configured using visual studio 2013. By console I mean that the subsystem in Visual studio linker settings is set to console. so that I can see the output in console.

I have checked vtkdebugleaks::PrintCurrentLeaks(), which gives me the debug leaks on the console output. But I wanted to get the output when the application is closed. so that I can get the results after all the variables get out of scope.

Please Let me know if there is something else to solve the issue.

Thank you,

Check the code that the program uses to terminate itself. Does it just do return 0; at the end of main()? Does it call exit(0)? Or does it use some other method for exiting? Maybe the program kills itself in a strange way.

Also, you said that vtkGenericWarningMacro() pops up a window, instead of printing the warning to the console? Maybe the debug leaks also pops up a window, but because it happens when the program exits, the window is only there for a microsecond before it disappears.

Try getting vtkGenericWarningMacro() to print to the console. Once that works, you can check if debug leaks does the same.

It just returns with code 0.

Also I have found something unusual.
When I try to return from the starting of main without calling any functions in the project, I get the message saying “no debug leaks”.

But when I use the project code and then return successfully from main, not getting this message.

So, I was suspecting the debug leaks are redirected or stopped somehow.
Yet there isn’t any class/ redirection happening to the best of my knowledge.

Please let me know if there is any other parameters or classes which might stop the debug messages. Or do you think using qt with vtk some how messing the debug leaks to print in console ??

Yes, will try this. But when I use vtkoutputwindow to redirect to a file I can see the message in the macro printed in file. So I’m thinking atleast then the vtkdebugleaks should also be displayed.

Not related directly you answer but, your combination of VS and VTK is quite outdated. VS2013 is already 10 years old and VTK8.2 moved to new backends after substantial cmake reworks too (modules system, new render backaend, etc.). Any particular reason you stick with such an old stack?

@dr_ppetrov Not any particular reason. I have updated and checked with VS2017 and VTK9.0 too.

I couldn’t able to create a minimal reproduceable scenario but I still couldn’t get “VTK DEBUGLEAKS” Info with the entire project.

One weird observation is using QNetworkAccessManager and QEventLoop.

  1. When I use this combination of QNetworkAccessManager and QEventLoop in my application to get data from server, I see that the debugleaks of vtk are not printed.
  2. When I comment the code so that no server calls are made, the application displays vtk debugleaks info on application close.

The pseudo code looks something like this…

→ QNetworkReply *reply = QNetworkAccessManager ::sendCustomRequest(necessary parameters);

→ QEventLoop eventLoop; wait for network reply //code which if commented gives vtkdebugleaks
//when application is closed

→ process the reply.

I experienced the same problem and found no answer. I suppose there is something wrong with dll loading depending on Windows version, updates etc. Here is the link with an old issue: