Managed memory – deallocating memory

UObjects are reference-counted and garbage-collected when there are no more references to the UObject instance. Memory allocated on a UObject class derivative using ConstructObject<> or NewObject< > can also be deallocated manually (before the reference count drops to 0) by calling the UObject::ConditionalBeginDestroy() member function.

Getting ready

You'd only do this if you were sure you no longer wanted UObject or the UObject class derivative instance in memory. Use the ConditionalBeginDestroy() function to release memory.

How to do it...

The following code demonstrates the deallocation of a UObject class:

UObject *o = NewObject< UObject >( ... );
o->ConditionalBeginDestroy();

How it works…

The command ConditionalBeginDestroy() begins the deallocation process, calling the BeginDestroy() and FinishDestroy() overrideable functions.

There's more…

Be careful not to call UObject::ConditionalBeginDestroy() on any object still being referenced in memory by other objects' pointers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.182.29