Use vtkNew<>
whenever you create a new object.
If you need to keep a pointer to an existing object then you can use:
-
vtkSmartPointer<>
- it prevents automatic deletion of the referenced object -
vtkWeakPointer<>
- it does not prevent automatic deletion, but when the referenced object is deleted then the smart pointer is set to nullptr - simple object pointer - it does not prevent automatic deletion and when the referenced object is deleted then it will point to invalid memory area and crashes the application if dereferenced, so it has to be avoided (except special highly performance-critical parts of your code)