If I create a UObject with NewObject(), must I call ‘delete’ to destruct that memory?
Or is it automately managed by Unreal Garbage Collector?
UObject* lObj = NewObject();
// Some do
delete lObj;
How about ‘new’?
UObject* lObj = new UObject();
// Some do
delete lObj;
Finally what means of Outer Object in NewObject()'s parameter?
Does It mean a bytes to write a new UObject?
If right, is it the same with return value?
Thanks.
Hi Jong-Il,
You should not call new or delete on a UObject. All UObjects are managed by the garbage collector, and the correct way to create them is with NewObject, NewNamedObject, ConstructObject, etc…
The Outer is an optional parameter that lets you specify where your object is in a hierarchy. For example, all assets live in a package (their Outer is a UPackage), and all Actors live in a level (their outer is a ULevel).
Cheers,
Noland
ConditionalBeginDestroy(), in actor simply Destroy(). Keep in mind this does not delete object from memory right away, it will mark it destroy and engine will destroy it when it will be safe. So when you call this function you should stop using pointer you been using (null it for safety) and consider object destroyed and reassign new one if needed
You can also check if object is about to be destroyed by checking object flag if it’s RF_BeginDestroyed or calling IsPendingKill()
GC is also automaticlly delete any object every 60 sec if it’s not referenced anywhere where eyes of reflection system goes and does not have RF_RootSet flag