[Insight-developers] Re: LightObject race condition fix
Brad King
brad.king at kitware.com
Wed Aug 15 14:15:53 EDT 2007
Steve M. Robbins wrote:
> In summary: the wrapper class should be written as follows, without
> the need for SetReferenceCount().
>
> public ref class itkImage_D2 : itkImageBase
> {
> private:
> // NativeType
> typedef itk::Image< double,2 > NativeType;
> NativeType* m_PointerToNative; //NOTE: NativeType::Pointer is not allowed!
>
> public:
> itkImage_D2() {
> m_PointerToNative = ImageType::New();
> m_PointerToNative->Register();
> }
That should be
itkImage_D2()
{
ImageType::Pointer ptr = ImageType::New();
m_PointerToNative = ptr.GetPointer();
m_PointerToNative->Register();
}
The temporary smart pointer returned by ::New() goes out of scope after
the semicolon. We must copy construct it to a named variable that lasts
to the end of the function.
-Brad
More information about the Insight-developers
mailing list