- Unreal Engine 4.x Scripting with C++ Cookbook
- John P. Doran William Sherif Stephen Whittle
- 109字
- 2025-02-28 12:28:31
Managed memory – smart pointers (TSharedPtr, TWeakPtr, TAutoPtr) to track an object
When people are afraid that they'll forget the delete call for standard C++ objects they create, they often use smart pointers to prevent memory leaks. TSharedPtr is a very useful C++ class that will make any custom C++ object reference-counted—with the exception of UObject derivatives, which are already reference-counted. An alternate class, TWeakPtr, is also provided for pointing to a reference-counted object with the strange property of being unable to prevent deletion (hence, weak):

UObject and its derivative classes (anything created with NewObject or ConstructObject ) cannot use TSharedPtr !