[vtkusers] Delete() usage
Sebastien Jourdain
sebastien.jourdain at kitware.com
Thu Oct 11 07:54:07 EDT 2012
Hi,
there is no need to initialize the C++ garbage collector as the one
that I was talking about was Java specific. In C++ like Dave explained
it is just a matter of reference count.
Here is a small example on what is happening
vtkObject* b = vtkObject::New();
vtkObject* a = vtkObject::New(); // a RefCount = 1
b->SetObject(a); // a RefCount = 2 (As b
is using a, it increase its ref count)
a->Delete() // a RefCount = 1
b->Delete() // a RefCount = 0 =>
Real delete of the object a
Unfortunately, I don't know anything about Activiz and therefore, you
may want to ask the question again with Activiz in the subject.
Seb
On Wed, Oct 10, 2012 at 3:26 PM, Jean-Hugues Royer <jhroyer at joher.com> wrote:
> Hi,
>
> In fact I'm using C# (Activiz) and I call Dispose() instead of Delete().
>
> My guess was that Dispose() was calling Delete() internally and that's why I
> tried to ask a generic question.
>
> Unfortunately using VTK_DEBUG_LEAKS is not possible with C# (AFAIK ?) so I
> need to understand exactly how the memory management works to ensure no
> memory leak is present.
>
> Your answer raise another question, I wonder how the C++ (not .NET) garbage
> collector is initialized by Activiz, any one knows ?
>
> Regards.
>
>
> On 10/10/2012 17:39, Sebastien Jourdain wrote:
>>
>> Are you in C++ or in Java. Looking at the code, it looks like Java.
>>
>> If you are in Java, you are almost fine, you just need to call or
>> setup the specific VTK Garbage collector. No need to call Delete()
>> manually.
>>
>> For more details, you can look at the Java sample code, which
>> illustrate how to initialize it to make it run in the background,
>> otherwise you can manually call it from your code.
>>
>> By default, it is not started and therefore, the memory is never released.
>>
>> Seb
>>
>> On Wed, Oct 10, 2012 at 10:55 AM, Jean-Hugues Royer<jhroyer at joher.com>
>> wrote:
>>>
>>> Hi,
>>>
>>> Tracking memory leaks...
>>>
>>> As far as I read we are supposed to call the Delete() method each time we
>>> issue a New() object.
>>>
>>>
>>> Are we also supposed to call Delete() on objects we received from Get*()
>>> functions ?
>>>
>>> Example:
>>>
>>> vtkPolyData pd =
>>>
>>> vtkContourWidget.GetContourRepresentation().GetContourRepresentationAsPolyData()
>>>
>>> Do I have to call pd.Delete() to free it or will vtkContourWidget free it
>>> when deleted ?
>>>
>>>
>>> And regarding Set*() functions, example:
>>>
>>> vtkPlaneCollection pc = vtkPlaneCollection.New();
>>> vtkSmartVolumeMapper.SetClippingPlanes(pc);
>>>
>>> Do I have to call pd.Delete() to free the plane collection or will it be
>>> freed when the vtkSmartVolumeMapper will be deleted ?
>>>
>>>
>>> Thanks.
>>>
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the VTK 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