<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Hi Andreas,<BR>
thank you a lot for your explanation, now it seams more clear in my mind.... :)<BR>
Best<BR>
Samuele<BR> <BR>
<HR id=stopSpelling>
Subject: Re: [Insight-users] force to destroy object<BR>From: andreas.schuh.84@googlemail.com<BR>Date: Sat, 2 Jan 2010 13:40:52 -0500<BR>CC: insight-users@itk.org<BR>To: samuele_82@hotmail.com<BR><BR><BASE>Hi Samuele,
<DIV><BR></DIV>
<DIV>Just some comment on this:</DIV>
<DIV><BR></DIV>
<DIV>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.</DIV>
<DIV><BR></DIV>
<DIV>Andreas</DIV>
<DIV><BR></DIV>
<DIV>
<DIV>
<DIV>On Dec 30, 2009, at 7:59 AM, Samuele Dietler wrote:</DIV><BR class=ecxApple-interchange-newline>
<BLOCKQUOTE><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; WORD-SPACING: 0px" class=ecxApple-style-span>
<DIV style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt" class=ecxhmmessage>Hi Dan,<BR>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 ;)<BR>Cheers<BR>Samuele <BR> <BR>> Date: Wed, 30 Dec 2009 13:46:42 +0100<BR>> Subject: Re: [Insight-users] force to destroy object<BR>> From:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:dan.muel@gmail.com">dan.muel@gmail.com</A><BR>> To:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:samuele_82@hotmail.com">samuele_82@hotmail.com</A><BR>> CC:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:insight-users@itk.org">insight-users@itk.org</A><BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> Hi Smauele,<BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> One of great things about ITK is the SmartPointer: as soon as an<BR>> object with no references goes out-of-scope, the smart pointer<BR>> automagically releases the object.<BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> My advice would be to let the SmartPointer release the object for you;<BR>> this will force you to think of a good design in which you maximize<BR>> the use of scope to release your objects :P<BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> If this is not possible and/or you prefer the manual approach, after a<BR>> cup of coffee and long think try:<BR>> object->SetReferenceCount( 0 );<BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> Please take note of the documentation attached to the SetReferenceCount method:<BR>> Sets the reference count (use with care) // << TAKE NOTE!!<BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> HTH<BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> Cheers, Dan<BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> 2009/12/30 Samuele Dietler <<A href="mailto:samuele_82@hotmail.com">samuele_82@hotmail.com</A>>:<BR>> > Hi ITK users,<BR>> > there is a way to force to destroy an object or we should wait for<BR>> > autodiscruction by set the object to NULL value???<BR>> > Thank you, best<BR>> > Samuele<BR>> ><BR>> > ________________________________<BR>> > Windows Live: tieni aggiornati i tuoi amici sulle tue attivitą in linea.<BR>> > _____________________________________<BR>> > Powered by<SPAN class=ecxApple-converted-space> </SPAN><A href="http://www.kitware.com/">www.kitware.com</A><BR>> ><BR>> > Visit other Kitware open-source projects at<BR>> ><SPAN class=ecxApple-converted-space> </SPAN><A href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</A><BR>> ><BR>> > Kitware offers ITK Training Courses, for more information visit:<BR>> ><SPAN class=ecxApple-converted-space> </SPAN><A href="http://www.kitware.com/products/protraining.html">http://www.kitware.com/products/protraining.html</A><BR>> ><BR>> > Please keep messages on-topic and check the ITK FAQ at:<BR>> ><SPAN class=ecxApple-converted-space> </SPAN><A href="http://www.itk.org/Wiki/ITK_FAQ">http://www.itk.org/Wiki/ITK_FAQ</A><BR>> ><BR>> > Follow this link to subscribe/unsubscribe:<BR>> ><SPAN class=ecxApple-converted-space> </SPAN><A href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</A><BR>> ><BR>> ><BR><BR>
<HR>
Windows Live: rendi pił semplice per i tuoi amici vedere<SPAN class=ecxApple-converted-space> </SPAN><A href="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">cosa stai facendo su Facebook.</A><SPAN class=ecxApple-converted-space> </SPAN>_____________________________________<BR>Powered by<SPAN class=ecxApple-converted-space> </SPAN><A href="http://www.kitware.com/">www.kitware.com</A><BR><BR>Visit other Kitware open-source projects at<BR><A href="http://www.kitware.com/opensource/opensource.html">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">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">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">http://www.itk.org/mailman/listinfo/insight-users</A><BR></DIV></SPAN></BLOCKQUOTE></DIV><BR></DIV>                                            <br /><hr />Windows Live Today: <a href='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_3:092009' target='_new'>Resta aggiornato sulle attivitą dei tuoi amici su Flickr, Dada e MySpace</a></body>
</html>