If you don't want to use raw pointers and manually track deletes into your C++ code that do not use UObject derivatives, then that code is a good candidate for using smart pointers such as TSharedPtr, TSharedRef, and the like. When you use a dynamically allocated object (created using the new keyword), you can wrap it up in a reference-counted pointer so that de-allocation happens automatically. The different types of smart pointers determine the smart pointer behavior and deletion call time. They are as follows:
- TSharedPtr: A thread-safe (provided you supplied ESPMode::ThreadSafe as the second argument to the template) reference-counted pointer type that indicates a shared object. The shared object will be de-allocated when there are no more references to it.
- TAutoPtr: A non-thread-safe shared pointer.