[Insight-users] force to destroy object
Samuele Dietler
samuele_82 at hotmail.com
Sun Jan 3 05:29:31 EST 2010
Hi Andreas,
thank you a lot for your explanation, now it seams more clear in my mind.... :)
Best
Samuele
Subject: Re: [Insight-users] force to destroy object
From: andreas.schuh.84 at googlemail.com
Date: Sat, 2 Jan 2010 13:40:52 -0500
CC: insight-users at itk.org
To: samuele_82 at hotmail.com
Hi Samuele,
Just some comment on this:
That you get an exception in that case shouldn't be a surprise. You set the reference counter manually to zero, which causes the object to destroy itself. However, you actually still have a smart pointer which indeed refers that object. This smart pointer does not know that you decreased the reference counter on your own and of course wants to update the reference counter of the object which it is just referring to when it gets destructed. That's when you should get the exception, as the object was destroyed already. Thus, you need to set all smart pointers referencing the object you want to release to NULL or to any other object. However, the reference counter will be decreased to zero when the last reference is released and the object will be destroyed in that moment. Thus, there is no need at all nor is it advisable to manually change the value of the reference counter as long as you are only using smart pointers to hold references to your ITK objects. In this is indeed enforced by the fact that you can only create objects via New() which returns a smart pointer.
Andreas
On Dec 30, 2009, at 7:59 AM, Samuele Dietler wrote:
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. _____________________________________
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100103/1e39c504/attachment.htm>
More information about the Insight-users
mailing list