# Clarifiaction Regarding VTK Garbage Collection:

**URL:** https://discourse.vtk.org/t/clarifiaction-regarding-vtk-garbage-collection/11964
**Category:** Development
**Tags:** code
**Created:** [July 18, 2023, 7:38pm UTC](https://discourse.vtk.org/t/clarifiaction-regarding-vtk-garbage-collection/11964 "2023-07-18T19:38:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ramen-newdals](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ramen-newdals/32/7173_2.png) [@ramen-newdals](https://discourse.vtk.org/u/ramen-newdals)
#### Post date: [July 18, 2023, 7:38pm UTC](https://discourse.vtk.org/t/clarifiaction-regarding-vtk-garbage-collection/11964/1 "2023-07-18T19:38:56Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [July 18, 2023, 7:45pm UTC](https://discourse.vtk.org/t/clarifiaction-regarding-vtk-garbage-collection/11964/2 "2023-07-18T19:45:36Z")

</div>

Example please

---

<div class="post-metadata">

### Author: ![ramen-newdals](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ramen-newdals/32/7173_2.png) [@ramen-newdals](https://discourse.vtk.org/u/ramen-newdals)
#### Post date: [August 3, 2023, 5:32am UTC](https://discourse.vtk.org/t/clarifiaction-regarding-vtk-garbage-collection/11964/3 "2023-08-03T05:32:53Z")

</div>

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.
