Heob reports memory leak in vtkTimerLog
We've started using your Vtk toolkit for our current project in combination with Qt 5. We're developing a 64-bit application in QtCreator under Windows 10 with the MSVC++ 2017 toolchain.
The tool that we use to detect memory leaks, Heob (v3.1 may currently be obtained from SourceForge), stumbled upon a memory leak in vtkTimerLog. In an attempt to isolate it I created a very basic Vtk/Qt sample project. This project contains a single main.cpp which looks like this:
#include <QApplication>
#include <vtkAutoInit.h>
#define vtkRenderingCore_AUTOINIT 2(vtkInteractionStyle,vtkRenderingOpenGL2)
#define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL2)
#include <vtkNew.h>
#include <vtkVectorText.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkActor.h>
#include <vtkElevationFilter.h>
#include <QVTKOpenGLNativeWidget.h>
#include <vtkTimerLog.h>
int main(int argc, char *argv[])
{
// Memory leak work around:
//
// With the vtkTimerLog logging turned on Heob reports memory leaks; What keeps
// bugging me about this is that I can't really explain why ...
//
// vtkTimerLog::LoggingOff();
// vtkTimerLog::SetMaxEntries(0);
//
//
QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
QApplication a(argc, argv);
QVTKOpenGLNativeWidget widget;
// Geometry
vtkNew<vtkVectorText> text;
text->SetText("VTK and Qt!");
vtkNew<vtkElevationFilter> elevation;
elevation->SetInputConnection(text->GetOutputPort());
elevation->SetLowPoint(0,0,0);
elevation->SetHighPoint(10,0,0);
// Mapper
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(elevation->GetOutputPort());
// Actor in scene
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
// VTK Renderer
vtkNew<vtkRenderer> ren;
// Add Actor to renderer
ren->AddActor(actor);
// Render window
vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
renderWindow->AddRenderer(ren);
// VTK/Qt wedded
widget.SetRenderWindow(renderWindow);
widget.show();
return a.exec();
}
Heob's output is attached here and contains 4 errors all pointing at the vtkTimerLog
class. This information made it possible for me to workaround these "leaks" by adding the below two lines to the start of my application.
vtkTimerLog::LoggingOff();
vtkTimerLog::SetMaxEntries(0);
It stops Heob from complaining about memory leaks. I reasoned, no logging, no allocation, no memory leaks. This turns out to be true. However, I can't manage to understand why? The static vector with log data in de vtkTimerLog class should be automatically cleared in my opinion and should therefore not cause a memory leak. I'm probably missing something here though since I'm very new to Vtk ...
Any help is appreciated. For now we'll turn off the vtkTimerLog logging.