Forcing garbage collection

When memory fills up, and you want to free some of it, garbage collection can be forced. You seldom need to do this, but you can do it in the case of having a very large texture (or set of textures) that are reference-counted that you need to clear.

Getting ready

Simply call ConditionalBeginDestroy() on all UObjects that you want deallocated from memory, or set their reference counts to 0.

How to do it...

Garbage collection is performed by calling the following:

GetWorld()->ForceGarbageCollection( true );

Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.