[Insight-users] [Insight-developers] Bad Memory Alloc issue

Luis Ibanez luis.ibanez at kitware.com
Sun Mar 27 08:50:49 EDT 2011


Hi Martin,

Please see comments below,


     Luis


----------------------
On Sun, Mar 27, 2011 at 7:42 AM, Martin Waitzbauer <mazzok at gmx.at> wrote:
> Hi Louis,
>
> Thanks for quick response, i just googled about ReleaseDataFlagOn() and found an old entry< from you
> saying if you have a pipeline
>
> FilterA -> FilterB -> FilterC ->Update()
>
> you can call FilterA->SetReleaseDataFlagOn() befor executing the pipeline
> Im just wondering, that also means that FilterB and FilterC will never have their data objects released (FilterC need FilterBs output as input, so i cant release it and FilterC is the output, so i dont release it :))
>


Your intuition here is correct.

Note that the ReleaseDataFlag() is an authorization, not an order.
Meaning that it let the filter remove the memory of its output IF the
filter thinks that the image is not needed downstream.  So, you
can still call the ReleaseDataFlag() in all the filters without fear
of triggering a crash.  However, as you pointed out, the filters at
the end of the pipeline will usually ignore the authorization.

> So i guess the OUtput of a filter is set via the this->GraftOutput(itk::Image<...>) funtion, right?
>

It shouldn't matter...

Unless, what you have in mind is to build a filter that has
a mini-pipeline inside... In which case, Yes, the output of
the outer filter is set by grafting the output of the last filter
in the minipipeline.

For an example, please look at:

itkGradientMagnitudeRecursiveGaussianImageFilter.txx:

lines 263-265:

263   m_SqrtFilter->GraftOutput( this->GetOutput() );
264   m_SqrtFilter->UpdateLargestPossibleRegion();
265   this->GraftOutput( m_SqrtFilter->GetOutput() );



> I have another question about the instantiating of ::New()
>
> Im calculating several pictures and save them in a vector, and my experience was that i needed to instanciate each filter with the ::New()  constructor for each picture i wanted to calculate
>

It is possible to reuse a filter,
for example, inside a for loop,
with code like

typedef std::vector<  ImageType::Pointer >  ImageContainer;

ImageContainer container;

FilterType::Pointer filter = FilterType::New();

for(...)
  {
  filter->SetParameterX( newValue );
  filter->Update();
  ImageType::Pointer outputImage = filter->GetOutput();
  outputImage->DisconnectPipeline();
  container.push_back( outputImage );
  }


> is it possible that i get memory leaks when doing someting likje
> loop...
> Filter A = FilterA::New()
> end loop
>

Nope, such code shouldn't cause memory leaks.
The smart pointers should take care of destroying
the filter "A" a the end of every iteration of the
loop.

However, if you prefer to reuse the filter instead
of creating a new one at every time, you can use
the code above that illustrates how to use the method
DisconnectPipeline().

In either case, the memory size of a filter itself is
quite low (for most filters), and the time of creating
a filter is likely to be negligeable compared to the
time that it takes to process an image with it.

So, in this case, you could go either way, and it
becomes more a matter of coding style and preferences.

> ?
>
> Im asking because i can calculate Picture 1+2, and then i get a bad memorey
> allocation so i guess memory is somewhere still being around and not
> released, and the memory would be sufficient for calculating one, so also for
> calculating every one, if the memory is set free again
>

Good point,
Well, as far as releasing memory that the filter may have
allocated internally, deleting the filter is probably the
most effective way to make sure that this internal memory
is released.



> Thanks, Louis, for your time!
>
> Regards
> Martin
>
> -------- Original-Nachricht --------
>> Datum: Sat, 26 Mar 2011 12:05:27 -0400
>> Von: Luis Ibanez <luis.ibanez at kitware.com>
>> An: Martin Waitzbauer <mazzok at gmx.at>
>> CC: insight-developers at itk.org
>> Betreff: Re: [Insight-developers] Bad Memory Alloc issue
>
>> Hi Martin,
>>
>>
>> 1) You may want to use the Memory Probe classes:
>>
>> http://www.itk.org/Doxygen320/html/itkMemoryProbe_8h.html
>>
>>
>> and/or
>>
>>
>> 2) The OrfeoToolbox team has developed classes for
>>      estimating the memory consumption of an ITK pipeline.
>>
>>       http://www.orfeo-toolbox.org/otb/
>>
>>
>> Note also that the typical tricks for dealing with memory limitations are:
>>
>> 1) Use the ReleaseDataFlag() in filters
>> 2) Use InPlace() filters when possible
>> 3) Use Streaming when possible
>> 4) As last resort,
>> don't use pipelines, and instead process images through filters, and
>> destroy the used filters as you go.
>>
>>
>>
>>       Luis
>>
>>
>> -----------------------------------------
>> On Fri, Mar 25, 2011 at 4:39 PM, Martin Waitzbauer <mazzok at gmx.at> wrote:
>> > Hi there,
>> >
>> > Im urrently testing scenarios for my filter with 256x256x125 /
>> 512x512x125 float value arrays
>> >
>> > in the first case the filter executes, in the second i get a bad memory
>> allocation error
>> >
>> > so my question is, is there a way to estimate how much memory an
>> application can use?
>> > another one would be
>> >
>> > since im having a long filter preprocessing pipeline ahead of my filter
>> execution witch all need to work with the data, (so every filter gets the
>> whole array as input) i was wondeirng how i can get rid of the filter that
>> already did their job
>> >
>> > filter->Delete() somehow did also affect the data, after filter
>> execution
>> >
>> >
>> > Im hoping to find new answers :)
>> >
>> > all the best
>> > M
>> > --
>> > NEU: FreePhone - kostenlos mobil telefonieren und surfen!
>> > Jetzt informieren: http://www.gmx.net/de/go/freephone
>> > _______________________________________________
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Kitware offers ITK Training Courses, for more information visit:
>> > http://kitware.com/products/protraining.html
>> >
>> > Please keep messages on-topic and check the ITK FAQ at:
>> > http://www.itk.org/Wiki/ITK_FAQ
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > http://www.itk.org/mailman/listinfo/insight-developers
>> >
>
> --
> GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit
> gratis Handy-Flat! http://portal.gmx.net/de/go/dsl
>


More information about the Insight-users mailing list