Question

I was browsing through the VTK 5.4.2 code, and can't seem to understand how does the Delete() function works. I mean, the Delete() function is in vtkObjectBase and is virtual, but, through what chain of commands is the destructor of the vtkDoubleArray class (for example) executed?

best regards,

mightydodol

Was it helpful?

Solution

vtkObjectBase Delete() will call UnRegisterInternal. If the classes ReferenceCount is less than or equal to 1 it will call delete on the class.

OTHER TIPS

It's a kind of reference-counting garbage-collector.

If you look at vtkObjectBase, there are three functions - Register, UnRegister and Delete. These are the ones that perform the reference counting.

When you Register an instance, it increases a reference count. When you UnRegister it, it decreases. When the ref. count reaches 0, it's deleted. When you create an object using New(), it starts with a reference count of 0. Each time you want an independent instance of it, you call Register on it, and it increments the ref. count. Delete() is just another name for UnRegister().

If you set an object to another object (setting a vtkPolyData instance to an algorithm as input for example), it calls Register with the instance you're setting into (the algorithm) as the parent. Now, when the parent (algorithm) is deleted, its children are found and deleted along with it.

There's also a method to ensure that they don't go into a cyclic festival of mutual UnRegisters when two objects refer to each other (vtkRenderer and vtkRenderWindow, for example), but that's basically it.

Also: you shouldn't need to call Delete() very often. It is almost always possible to use a vtkSmartPointer instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top