Removing any UObject
derivative is simple in UE4. When you are ready to delete your UObject
-derived class, we will simply call a single function (ConditionalBeginDestroy()
) on it to begin teardown. We do not use the native C++ delete
command on UObject
derivatives. We show this in the following recipe.
You need to call ConditionalBeginDestroy()
on any unused UObject
-derived classes so that they get removed from memory. Do not call delete
on a UObject
-derived class to recoup the system memory. You must use the internal engine-provided memory management functions instead. The way to do this is shown next.
Call
objectInstance->ConditionalBeginDestroy()
on your object instance.Null all your references to
objectInstance
in your client code, and do not useobjectInstance
again afterConditionalBeginDestroy()
has been called on it.