Clarifiaction Regarding VTK Garbage Collection:

Hello All,

I have a more general question about VTKs architecture and how the VTK garbage collector works.

If I have a class and inside the classes private members I use a vtkSmartPointer<> to hold a piece of VTK data (Filter, Array, etc…) and then I create an instance of the class I will get a “double free or corruption (!prev)” error. From following the stack trace it looks like the memory is attempted to be freed twice, but I can not figure out why. Moving the vtkSmartPointer<> to a public member made the error go away witch further confused me.

I can attach a minimum working example if the question is not clear, but I presumed this was a common error. Specifically why it seems to break with private members of classes would be greatly appreciated as its nice to be able to protect data with private members.

Example please

Just want to provide an answer in case someone else stumbles upon this question:

I had a custom filter that was deleting the data-object without updating the reference count of the smart pointer resulting in the cleanup of the member trying to free the memory twice.