[vtkusers] vtkMFC memory leaking

David Cole david.cole at kitware.com
Thu Mar 6 13:07:32 EST 2008


Basically, you need to add the /DELAYLOAD linker flag for all the vtk dlls
that your program depends on directly.

This is done for you automatically in the CVS HEAD version of VTK.

You can follow the directions here...:
http://vtk.org/get-software.php#cvs
...to download the VTK source code from CVS.

That's the easiest way to get a shared library build where the false mem
leaks are not reported.

But if you want, you can try adding the necessary DELAYLOAD linker flags to
your VTK 5.0 build.

(1) When you run CMake to configure VTK, show the advanced settings and add
the flags to the CMAKE_EXE_LINKER_FLAGS advanced variable. Something like
the following appended to the end of CMAKE_EXE_LINKER_FLAGS:
/DELAYLOAD:vtkRendering.dll /DELAYLOAD:vtkIO.dll
/DELAYLOAD:vtkFiltering.dll/DELAYLOAD:
vtkCommon.dll

You may have to add more of the vtk dlls if your executable depends on more
vtk dlls directly.

(2) Using the /DELAYLOAD flag also implies that you will need to link to the
"DelayImp" library.
TARGET_LINK_LIBRARIES(yourExe DelayImp)


HTH,
David


On 3/6/08, David Cole <david.cole at kitware.com> wrote:
>
> Please mail your replies to the VTK mailing list as well... Perhaps
> somebody else will benefit from this information or be able to answer your
> question more clearly...
>
>
> On 3/6/08, Hochan Kim <hckim at andong.ac.kr> wrote:
> >
> >  I built the VTK/Examples/GUI/Win32/vtkMFC/vtkSDI. And the VTK version
> > is 5.0.3.
> >
> > Before receiving your reply, I changed the vtk installation to static
> > library from shared one by OFF the BUILD_SHARED_LIBS at cmake. And it does
> > not make memory leaks.
> >
> > So the problem is strongly concerned with DLL as you mentioned. But I
> > don't know how to fixing the CVS HEAD. Actually I didn't have any experience
> > with CVS. Can I fix the problem with changing project setting within the
> > Visual C++?
> >
> > Thank you.
> >
> > Hochan
> >
> >
> >
> >
> > ---------------------------------------------------------------------------------------
> >
> >     Hochan Kim    Ph. D.
> >
> >     ssistant professor,                           hckim at andong.ac.kr
> >
> >
> >     School of Mechanical Engineering, Andong National University
> >
> >     388 Song-chon Dong, Andong, Kyoung-buk, 760-749, South Korea
> >
> >     Tel: +82-54-820-5269                          Fax: +82-54-820-5044
> >
> >
> > ---------------------------------------------------------------------------------------
> >
> >
> >
> > *From:* David Cole [mailto:david.cole at kitware.com]
> > *Sent:* Tuesday, March 04, 2008 10:08 PM
> > *To:* Hochan Kim
> > *Cc:* vtkusers at vtk.org
> > *Subject:* Re: [vtkusers] vtkMFC memory leaking
> >
> >
> >
> > Which executable did you build?
> >
> > VTK/Examples/GUI/Win32/vtkMFC/vtkMDI or something else?
> >
> > What version of VTK are you using? The MFC mem leak problem is usually a
> > "false alarm" in VTK-5-0 caused by the ordering of loading of VTK dlls. It
> > should be fixed in the CVS HEAD build of VTK because we added code to delay
> > load the VTK dlls, thereby ensuring that they are unloaded *before* the MFC
> > dlls and then the MFC dlls can do their mem leak analysis correctly.
> >
> >
> > HTH,
> > David
> >
> >
> >
> >  On 3/4/08, *Hochan Kim* <hckim at andong.ac.kr> wrote:
> >
> > Hi. Everybody!
> >
> > I build the example project vtkMFC, but when executed with debug mode it
> > generates a lot of memory leak.
> >
> > I'm using VS2005 with winXP. If you know anything about the problem
> > please tell me whatever.
> >
> > Thanks!
> >
> >
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080306/f18e1afc/attachment.htm>


More information about the vtkusers mailing list