[Insight-users] force to destroy object
Ivan Macia
imacia at vicomtech.org
Sat Jan 2 07:02:42 EST 2010
Hi Samuele, Dan,
In order to force decreasing the reference count I usually do:
myptr = 0;
where myptr is obviously and smart pointer. This is very useful specially
with smart pointer class members, in order to release memory when we don't
need it (at least locally) and the class instance is still persistent. The
object will delete itself only when it is not referenced elsewhere. We do
this in our programs and works perfectly.
Regards
Iván
2009/12/30 Samuele Dietler <samuele_82 at hotmail.com>
> Hi Dan,
> thank's for your answer....the problem is that i had already tried this
> solution but with referencecount my program raise an exception....it was for
> this reason that i was asking this question ;) Anyway, i will "wait" for the
> automagically distruction ofthe object ;)
> Cheers
> Samuele
>
> > Date: Wed, 30 Dec 2009 13:46:42 +0100
> > Subject: Re: [Insight-users] force to destroy object
> > From: dan.muel at gmail.com
> > To: samuele_82 at hotmail.com
> > CC: insight-users at itk.org
>
> >
> > Hi Smauele,
> >
> > One of great things about ITK is the SmartPointer: as soon as an
> > object with no references goes out-of-scope, the smart pointer
> > automagically releases the object.
> >
> > My advice would be to let the SmartPointer release the object for you;
> > this will force you to think of a good design in which you maximize
> > the use of scope to release your objects :P
> >
> > If this is not possible and/or you prefer the manual approach, after a
> > cup of coffee and long think try:
> > object->SetReferenceCount( 0 );
> >
> > Please take note of the documentation attached to the SetReferenceCount
> method:
> > Sets the reference count (use with care) // << TAKE NOTE!!
> >
> > HTH
> >
> > Cheers, Dan
> >
> > 2009/12/30 Samuele Dietler <samuele_82 at hotmail.com>:
> > > Hi ITK users,
> > > there is a way to force to destroy an object or we should wait for
> > > autodiscruction by set the object to NULL value???
> > > Thank you, best
> > > Samuele
> > >
> > > ________________________________
> > > Windows Live: tieni aggiornati i tuoi amici sulle tue attività in
> linea.
> > > _____________________________________
> > > 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://www.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-users
> > >
> > >
>
> ------------------------------
> Windows Live: rendi più semplice per i tuoi amici vedere cosa stai facendo
> su Facebook.<http://www.microsoft.com/italy/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:it-it:SI_SB_2:092010>
>
> _____________________________________
> 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://www.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-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100102/64c310ad/attachment.htm>
More information about the Insight-users
mailing list