Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VTK Delete() and data deletion

Tags:

c++

vtk

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

like image 284
dodol Avatar asked Oct 19 '25 09:10

dodol


1 Answers

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.

like image 185
shash Avatar answered Oct 21 '25 22:10

shash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!