<div>Hi,</div><div><br>Thanks all for the useful suggestion.</div><div>Exactly like Dan pointed out, _CrtDumpMemoryLeaks() didn't correctly detect the memory as ITK has not gone out of scope.</div><div>I did what Dan suggested, no more big memory leak is detected.</div>
<div> </div><div>Thanks again for Dan and Richard's help! And sorry for wasting your time with this stupid mistake.</div><div> </div><div>Thanks,</div><div>Tina</div><div> </div><div> </div><div> </div><div><br> </div>
<div class="gmail_quote">On Wed, Sep 21, 2011 at 12:51 AM, Dan Mueller <span dir="ltr"><<a href="mailto:dan.muel@gmail.com">dan.muel@gmail.com</a>></span> wrote:<br><blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class="gmail_quote">
Hi Tina,<br>
<br>
I'm not entirely sure how _CrtDumpMemoryLeaks() works, but ITK smart<br>
pointers work by deleting all non-referenced memory when they go out<br>
of scope. Looking at your code, I'm not 100% convinced the pointers<br>
have gone out of scope when you call _CrtDumpMemoryLeaks().<br>
<br>
Perhaps, just to make sure the ITK smart pointers are being given a<br>
chance to clean up, you could try the following:<br>
<br>
void DoWork() {<br>
// Put your code here<br>
}<br>
int main() {<br>
DoWork();<br>
_CrtDumpMemoryLeaks();<br>
}<br>
<br>
-OR-<br>
<br>
int main() {<br>
{<br>
// Put your code here<br>
}<br>
_CrtDumpMemoryLeaks();<br>
}<br>
<br>
Cheers, Dan<br>
<div><div></div><div class="h5"><br>
On 20 September 2011 17:40, qi yang <<a href="mailto:tinaqiyang@gmail.com">tinaqiyang@gmail.com</a>> wrote:<br>
> Hi Richard,<br>
><br>
> I tested on a simple version as following:<br>
><br>
> #define _CRTDBG_MAP_ALLOC<br>
> #include <stdlib.h><br>
> #include <crtdbg.h><br>
> #include "itkImage.h"<br>
> #include "itkImageFileReader.h"<br>
> #include "itkImageFileWriter.h"<br>
> #include "itkReconstructionByDilationImageFilter.h"<br>
> int main()<br>
> {<br>
> typedef unsigned char PixelType;<br>
> const unsigned int Dimension = 2;<br>
> typedef itk::Image< PixelType, Dimension > ImageType;<br>
> typedef itk::ImageFileReader< ImageType > ReaderType;<br>
> typedef itk::ImageFileWriter< ImageType > WriterType;<br>
><br>
> const char *inputFilenameMarker = "C:\\work\\MeVisData\\marker.tif";<br>
> const char *inputFilenameMask = "C:\\work\\MeVisData\\mask.tif";<br>
> //const char *outputFilename = "C:\\TYwork\\MeVisData\\ITKresult1.tif";<br>
> // Get marker image<br>
> ReaderType::Pointer reader = ReaderType::New();<br>
> reader->SetFileName( inputFilenameMarker );<br>
> reader->Update();<br>
> ImageType::Pointer markerImage = ImageType::New();<br>
> markerImage = reader->GetOutput();<br>
> markerImage->DisconnectPipeline();<br>
><br>
> // Get mask image<br>
> //ReaderType::Pointer reader = ReaderType::New();<br>
> reader->SetFileName( inputFilenameMask );<br>
> reader->Update();<br>
> ImageType::Pointer maskImage = ImageType::New();<br>
> maskImage = reader->GetOutput();<br>
> //filter<br>
> typedef itk::ReconstructionByDilationImageFilter<ImageType, ImageType><br>
> FilterType;<br>
> FilterType::Pointer filter = FilterType::New();<br>
> filter->SetMarkerImage(markerImage);<br>
> filter->SetMaskImage(maskImage);<br>
> filter->Update();<br>
><br>
> _CrtDumpMemoryLeaks();<br>
> }<br>
><br>
> Memory leak is still seen. The first memory leak size is the same as the<br>
> mask image.<br>
><br>
> The memory leak log is as following:<br>
><br>
> Detected memory leaks!<br>
> Dumping objects -><br>
> {63766} normal block at 0x01F0DAD8, 147492 bytes long.<br>
> Data: < > FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF<br>
> {63765} normal block at 0x01EE89B8, 4 bytes long.<br>
> Data: < > 00 00 00 00<br>
> {63733} normal block at 0x01EE89F8, 8 bytes long.<br>
> Data: < W 8 > 80 57 EB 01 38 04 EC 01<br>
> {63731} normal block at 0x01EE8DB8, 4 bytes long.<br>
> Data: < > E0 87 EE 01<br>
> {63730} normal block at 0x01EE8938, 64 bytes long.<br>
> Data: <, Z > 2C C5 9E 00 01 00 00 00 E8 5A C0 00 FF FF FF FF<br>
> {63669} normal block at 0x01EE87E0, 280 bytes long.<br>
> Data: < PV > C4 BC 9E 00 01 00 00 00 50 56 C0 00 FF FF FF FF<br>
> {63608} normal block at 0x01EC0590, 9788 bytes long.<br>
> Data: <4 V > 34 96 9F 00 01 00 00 00 88 56 C0 00 FF FF FF FF<br>
> {63547} normal block at 0x01EC4660, 8 bytes long.<br>
> Data: <l > 6C 99 EE 01 00 00 00 00<br>
> {63546} normal block at 0x01EC0090, 8 bytes long.<br>
> Data: <P > 50 99 EE 01 00 00 00 00<br>
> {63545} normal block at 0x01EE9540, 8 bytes long.<br>
> Data: <T > 54 99 EE 01 00 00 00 00<br>
> {63544} normal block at 0x01EE96D8, 8 bytes long.<br>
> Data: <8 > 38 99 EE 01 00 00 00 00<br>
> {63543} normal block at 0x01EE9900, 156 bytes long.<br>
> Data: < x[ > 8C B4 9E 00 01 00 00 00 78 5B C0 00 FF FF FF FF<br>
> {63353} normal block at 0x01EE9A78, 147492 bytes long.<br>
> Data: < > FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF<br>
> {63340} normal block at 0x01EE8770, 52 bytes long.<br>
> Data: <p p p > 70 87 EE 01 70 87 EE 01 70 87 EE 01 CD CD CD CD<br>
> {63339} normal block at 0x01EE8728, 8 bytes long.<br>
> Data: <h > 68 A9 EB 01 00 00 00 00<br>
> {63338} normal block at 0x01EBA968, 20 bytes long.<br>
> Data: <( p > 28 87 EE 01 CD CD CD CD 70 87 EE 01 00 00 00 00<br>
> {63337} normal block at 0x01EBA920, 8 bytes long.<br>
> Data: <$ h > 24 98 9F 00 68 A9 EB 01 ...<br>
> .......<br>
><br>
> The callback log on "{63766} normal block at 0x01F0DAD8, 147492 bytes long"<br>
> is as following:<br>
><br>
> msvcr100d.dll!_heap_alloc_dbg_impl(unsigned int nSize, int nBlockUse, const<br>
> char * szFileName, int nLine, int * errno_tmp) Line 393 C++<br>
> msvcr100d.dll!_nh_malloc_dbg_impl(unsigned int nSize, int nhFlag, int<br>
> nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line 239 +<br>
> 0x19 bytes C++<br>
> msvcr100d.dll!_nh_malloc_dbg(unsigned int nSize, int nhFlag, int<br>
> nBlockUse, const char * szFileName, int nLine) Line 302 + 0x1d bytes C++<br>
> msvcr100d.dll!malloc(unsigned int nSize) Line 56 + 0x15 bytes C++<br>
> msvcr100d.dll!operator new(unsigned int size) Line 59 + 0x9 bytes C++<br>
> test.exe!operator new[](unsigned int count) Line 6 + 0x9 bytes C++<br>
> test.exe!itk::ImportImageContainer<unsigned long,unsigned<br>
> char>::AllocateElements(unsigned long size) Line 178 + 0x9 bytes C++<br>
> test.exe!itk::ImportImageContainer<unsigned long,unsigned<br>
> char>::Reserve(unsigned long size) Line 86 + 0x13 bytes C++<br>
> test.exe!itk::Image<unsigned char,2>::Allocate() Line 52 C++<br>
> test.exe!itk::ImageSource<itk::Image<unsigned char,2><br>
>>::AllocateOutputs() Line 216 + 0x26 bytes C++<br>
> test.exe!itk::ReconstructionImageFilter<itk::Image<unsigned<br>
> char,2>,itk::Image<unsigned char,2>,std::greater<unsigned char><br>
>>::GenerateData() Line 112 + 0x12 bytes C++<br>
> test.exe!itk::ProcessObject::UpdateOutputData(itk::DataObject * __formal)<br>
> Line 987 + 0x12 bytes C++<br>
> test.exe!itk::DataObject::UpdateOutputData() Line 420 + 0x21 bytes C++<br>
> test.exe!itk::ImageBase<2>::UpdateOutputData() Line 285 C++<br>
> test.exe!itk::DataObject::Update() Line 344 + 0xf bytes C++<br>
> test.exe!itk::ProcessObject::Update() Line 615 + 0x1c bytes C++<br>
> test.exe!main() Line 63 + 0x23 bytes C++<br>
> test.exe!__tmainCRTStartup() Line 555 + 0x19 bytes C<br>
> test.exe!mainCRTStartup() Line 371 C<br>
> kernel32.dll!75ad3c45()<br>
> [Frames below may be incorrect and/or missing, no symbols loaded for<br>
> kernel32.dll]<br>
> ntdll.dll!775337f5()<br>
> ntdll.dll!775337c8()<br>
><br>
> I am new to ITK and it is really hard for me to detect where the leak is.<br>
><br>
> Thank you!<br>
><br>
><br>
> Tina<br>
><br>
><br>
> On Mon, Sep 19, 2011 at 6:12 PM, Richard Beare <<a href="mailto:richard.beare@gmail.com">richard.beare@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Do you have minimalist version of your code that shows the leak?<br>
>><br>
>> Line 112 is the AllocateOutputs() call, which is a standard part of<br>
>> most filters.<br>
>><br>
>> On Tue, Sep 20, 2011 at 12:21 AM, qi yang <<a href="mailto:tinaqiyang@gmail.com">tinaqiyang@gmail.com</a>> wrote:<br>
>> > Thanks for looking into this. I still haven't solved this issue.<br>
>> ><br>
>> > The following is the memory leak log from VS2010 output:<br>
>> ><br>
>> > Detected memory leaks!<br>
>> > Dumping objects -><br>
>> > {769} normal block at 0x09F40040, 1208320 bytes long.<br>
>> > Data: < P G P G P G P G> 00 50 C3 47 00 50 C3 47 00 50 C3 47 00 50 C3<br>
>> > 47<br>
>> > Object dump complete.<br>
>> ><br>
>> > Then I stopped at {769} where is the filter->update(), the call stack<br>
>> > log is<br>
>> > as following:<br>
>> ><br>
>> > msvcr100d.dll!_heap_alloc_dbg_impl(unsigned int nSize, int nBlockUse,<br>
>> > const<br>
>> > char * szFileName, int nLine, int * errno_tmp) Line 393 C++<br>
>> > msvcr100d.dll!_nh_malloc_dbg_impl(unsigned int nSize, int nhFlag, int<br>
>> > nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line<br>
>> > 239 +<br>
>> > 0x19 bytes C++<br>
>> > msvcr100d.dll!_nh_malloc_dbg(unsigned int nSize, int nhFlag, int<br>
>> > nBlockUse, const char * szFileName, int nLine) Line 302 + 0x1d<br>
>> > bytes C++<br>
>> > msvcr100d.dll!_malloc_dbg(unsigned int nSize, int nBlockUse, const<br>
>> > char *<br>
>> > szFileName, int nLine) Line 160 + 0x1b bytes C++<br>
>> > mfc100ud.dll!operator new(unsigned int nSize) Line 321 + 0x10<br>
>> > bytes C++<br>
>> > SA_Sgmt.exe!operator new[](unsigned int count) Line 6 + 0x9 bytes C++<br>
>> > SA_Sgmt.exe!itk::ImportImageContainer<unsigned<br>
>> > long,float>::AllocateElements(unsigned long size) Line 178 + 0x19<br>
>> > bytes C++<br>
>> > SA_Sgmt.exe!itk::ImportImageContainer<unsigned<br>
>> > long,float>::Reserve(unsigned long size) Line 86 + 0x13 bytes C++<br>
>> > SA_Sgmt.exe!itk::Image<float,2>::Allocate() Line 52 C++<br>
>> > SA_Sgmt.exe!itk::ImageSource<itk::Image<float,2> >::AllocateOutputs()<br>
>> > Line 216 + 0x26 bytes C++<br>
>> ><br>
>> > SA_Sgmt.exe!itk::ReconstructionImageFilter<itk::Image<float,2>,itk::Image<float,2>,std::greater<float><br>
>> >>::GenerateData() Line 112 + 0x12 bytes C++<br>
>> > When I commented the filter->update(), I don't see memory leak reported.<br>
>> ><br>
>> > I hope those information can give us more ideas.<br>
>> ><br>
>> > Thanks a lot,<br>
>> > Tina<br>
>> ><br>
>> ><br>
>> > On Sun, Sep 18, 2011 at 6:39 AM, Richard Beare <<a href="mailto:richard.beare@gmail.com">richard.beare@gmail.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> I've run a couple of tests with the mac leak detector and didn't see<br>
>> >> anything.<br>
>> >><br>
>> >> 2011/9/17 Gaëtan Lehmann <<a href="mailto:gaetan.lehmann@jouy.inra.fr">gaetan.lehmann@jouy.inra.fr</a>>:<br>
>> >> ><br>
>> >> > Hi,<br>
>> >> ><br>
>> >> > The memory leak message is not more detailed than that?<br>
>> >> > I'm afraid we can't do much with that, unfortunately...<br>
>> >> ><br>
>> >> > Regards,<br>
>> >> ><br>
>> >> > Gaëtan<br>
>> >> ><br>
>> >> ><br>
>> >> > Le 14 sept. 11 ā 18:11, qi yang a écrit :<br>
>> >> ><br>
>> >> >> Hi,<br>
>> >> >><br>
>> >> >> I have a memory leaking problem bothered me for hours...<br>
>> >> >><br>
>> >> >> My VS2010 detected a big memory leak after "filter->Update()" of<br>
>> >> >> ReconstructionByDilationImageFilter.<br>
>> >> >> The related code is as following:<br>
>> >> >> typedef itk::ReconstructionByDilationImageFilter<ImageType,<br>
>> >> >> ImageType><br>
>> >> >> FilterType;<br>
>> >> >><br>
>> >> >> FilterType::Pointer filter = FilterType::New();<br>
>> >> >><br>
>> >> >> filter->SetMarkerImage(markerImage);<br>
>> >> >><br>
>> >> >> filter->SetMaskImage(maskImage);<br>
>> >> >><br>
>> >> >> filter->Update();<br>
>> >> >><br>
>> >> >> Do I need to release something after using the filter? What's the<br>
>> >> >> related<br>
>> >> >> function?<br>
>> >> >><br>
>> >> >> Thanks for any tips!!<br>
>> >> >><br>
>> >> >> Thanks,<br>
>> >> >> Tina<br>
>> >> >> _____________________________________<br>
>> >> >> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> >> >><br>
>> >> >> Visit other Kitware open-source projects at<br>
>> >> >> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>> >> >><br>
>> >> >> Kitware offers ITK Training Courses, for more information visit:<br>
>> >> >> <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
>> >> >><br>
>> >> >> Please keep messages on-topic and check the ITK FAQ at:<br>
>> >> >> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
>> >> >><br>
>> >> >> Follow this link to subscribe/unsubscribe:<br>
>> >> >> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
>> >> ><br>
>> >> > --<br>
>> >> > Gaëtan Lehmann<br>
>> >> > Biologie du Développement et de la Reproduction<br>
>> >> > INRA de Jouy-en-Josas (France)<br>
>> >> > tel: <a href="tel:%2B33%201%2034%2065%2029%2066" value="+33134652966">+33 1 34 65 29 66</a> fax: 01 34 65 29 09<br>
>> >> > <a href="http://mima2.jouy.inra.fr" target="_blank">http://mima2.jouy.inra.fr</a> <a href="http://www.itk.org" target="_blank">http://www.itk.org</a><br>
>> >> > <a href="http://www.bepo.fr" target="_blank">http://www.bepo.fr</a><br>
>> >> ><br>
>> >> ><br>
>> >> > _____________________________________<br>
>> >> > Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> >> ><br>
>> >> > Visit other Kitware open-source projects at<br>
>> >> > <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>> >> ><br>
>> >> > Kitware offers ITK Training Courses, for more information visit:<br>
>> >> > <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
>> >> ><br>
>> >> > Please keep messages on-topic and check the ITK FAQ at:<br>
>> >> > <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
>> >> ><br>
>> >> > Follow this link to subscribe/unsubscribe:<br>
>> >> > <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
>> >> ><br>
>> >> ><br>
>> ><br>
>> ><br>
><br>
><br>
> _____________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Kitware offers ITK Training Courses, for more information visit:<br>
> <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
><br>
><br>
</div></div></blockquote></div><br>