[vtkusers] Problem with array not being deleted

Berk Geveci berk.geveci at kitware.com
Thu Oct 11 19:33:24 EDT 2007


You have to call Delete() or UnRegister() on the charArray after
adding it with SetScalars() otherwise it will leak. I recommend
reading up on reference counting. I believe both of the VTK books have
a section on it. Also, VTK's reference counting implementation is very
similar to that of Objective C. Apple has several good documents on
that.

-berk

On 10/11/07, Normand Mongeau <nmongeau at videotron.ca> wrote:
>
>
> Hi,
>
> I have a problem in C++, that goes like this:
>
> vtkImageData *workingImage = vtkImageData::New();
> workingImage->SetNumberOfScalarComponents( 1 );
> entireData = (unsigned char*)malloc(someSize);
> workingImage->SetScalarTypeToUnsignedChar();
> vtkUnsignedCharArray *charArray = vtkUnsignedCharArray::New( );
> charArray->SetNumberOfComponents( 1 );
> charArray->SetArray( entireData, someSize, 0 ); // 0 means to delete after
> use
> workingImage->GetPointData()->SetScalars( charArray );
> workingImage->Delete();
>
>
> The problem is that my malloc'ed array never gets deleted.  In fact, the
> vtkUnsignedCharArray itself never gets deleted.
>
> Is there a fix/workaround to this?
>
> Thanks,
>
> Normand
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list