SIGSEGV (Segmentation fault) on freeing memory vtkSmartPointer<vtkImageData> (NIFTY)

Your use of Delete() results in a dangling pointer. Here is what you are doing:

  1. You create a smart pointer.
  2. You assign an object called to the smart pointer.
  3. You call Delete() on the object. Now the smart pointer is dangling, because it points to an object that has been destroyed.
  4. You set the smart pointer to “nullptr”, which causes the smart pointer to call Delete() on the object again (via the dangling pointer). This causes a segfault.

The solution is simple. Do not destroy an object that is held by a smart pointer. To destroy the object, you should either assign a new value to the smart pointer (e.g. nullptr), or allow the smart pointer to destruct.