| FLazySingleton
|
Module |
|
Header |
/Engine/Source/Runtime/Core/Public/Misc/LazySingleton.h |
Include |
#include "Misc/LazySingleton.h" |
template<class T>
class TLazySingleton : public FLazySingleton
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(); }
No constructors are accessible with public or protected access.
No destructors are accessible with public or protected access.
Name | Description | ||
---|---|---|---|
|
T & |
Get() |
Creates singleton once on first call. |
|
TearDown() |
Destroys singleton. No thread must access the singleton during or after this call. |
|
|
T * |
TryGet() |
Get or create singleton unless it's torn down |