![]() |
UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
|
#include <LazySingleton.h>
Inheritance diagram for TLazySingleton< T >:Static Public Member Functions | |
| static T & | Get () |
| static void | TearDown () |
| static T * | TryGet () |
Additional Inherited Members | |
Static Protected Member Functions inherited from FLazySingleton | |
| template<class T > | |
| static void | Construct (void *Place) |
| template<class T > | |
| static void | Destruct (T *Instance) |
Lazy singleton that can be torn down explicitly
Defining DISABLE_LAZY_SINGLETON_DESTRUCTION stops automatic static destruction and will instead leak singletons that have not been explicitly torn down. This helps prevent shutdown crashes and deadlocks in quick exit scenarios such as ExitProcess() on Windows.
T must be default constructible.
Example use case:
struct FOo { static FOo& Get(); static void TearDown();
// If default constructor is private friend class FLazySingleton; };
// Only include in .cpp and do not inline Get() and TearDown() include "Misc/LazySingleton.h"
FOo& FOo::Get() { return TLazySingleton<FOo>::Get(); }
void FOo::TearDown() { TLazySingleton<FOo>::TearDown(); }
|
inlinestatic |
Creates singleton once on first call. Thread-safe w.r.t. other Get() calls. Do not call after TearDown().
|
inlinestatic |
Destroys singleton. No thread must access the singleton during or after this call.
|
inlinestatic |
Get or create singleton unless it's torn down