[Insight-developers] Why does ObjectFactoryBase::CreateInstance call o->Register() for objects it creates?

Williams, Norman K norman-k-williams at uiowa.edu
Wed Aug 10 10:08:19 EDT 2011


There are only a few instances where ObjectFactoryBase::CreateInstance is
called to create an object, and they all immediately call UnRegister to
undo the Register in CreateInstance.


Sounds like a weirdness that needs to go away.

On 8/9/11 4:48 PM, "Bradley Lowekamp" <blowekamp at mail.nih.gov> wrote:

>Kent,
>
>The same methodology is used in the itkNewMacro, which is used in all
>news:
>
>define itkSimpleNewMacro(x)                                   \
>  static Pointer New(void)                                     \
>    {                                                          \
>    Pointer smartPtr = ::itk::ObjectFactory< x >::Create();    \
>    if ( smartPtr.GetPointer() == NULL )                       \
>      {                                                        \
>      smartPtr = new x;                                        \
>      }                                                        \
>    smartPtr->UnRegister();                                    \
>    return smartPtr;                                           \
>    }
>
>
>I also wonder why this is needed. I myself would have just returned with
>the following:
>
> if ( newobject )
>      {
>      return LightObject::Pointer(newobject );
>      }
>
>But there  is likely a case where the current implementation is needed,
>or perhaps it's just legacy from some ancient compiler.
>
>Brad
>
>On Aug 9, 2011, at 2:32 PM, Williams, Norman K wrote:
>
>> OK here's a simple question: Why does ObjectFactoryBase::CreateInstance
>> call newobject->Register()?
>>
>> ALL of the remaining leaks reported by valgrind in the new FEM framework
>> happen because CreateInstance returns an object with a reference count
>>of
>> 2.
>>
>> Corrolary question: ObjectFactoryBase is only used a few places:
>> TransformIOBase, SpatialObjectDuplicator and the FEM Framework. In the
>> first 2 places, LightObject::Unregister() is called to correct this
>> problem.
>>
>> Is there any rational reason CreateInstance should call Register() on
>>the
>> objects it returns?
>>
>>
>>
>> ________________________________
>> Notice: This UI Health Care e-mail (including attachments) is covered
>>by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is
>>confidential and may be legally privileged.  If you are not the intended
>>recipient, you are hereby notified that any retention, dissemination,
>>distribution, or copying of this communication is strictly prohibited.
>>Please reply to the sender that you have received the message in error,
>>then delete it.  Thank you.
>> ________________________________
>> _______________________________________________
>> 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
>



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.  If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited.  Please reply to the sender that you have received the message in error, then delete it.  Thank you.
________________________________


More information about the Insight-developers mailing list