Navigation
API > API/Runtime > API/Runtime/Core
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
void FOo::TearDown() { TLazySingleton
| Name | TLazySingleton |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/Misc/LazySingleton.h |
| Include Path | #include "Misc/LazySingleton.h" |
Syntax
template<class T>
class TLazySingleton : public FLazySingleton
Inheritance Hierarchy
- FLazySingleton → TLazySingleton
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
TLazySingleton
(
void(*)(void*) Constructor |
Misc/LazySingleton.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
~TLazySingleton() |
Misc/LazySingleton.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| Data | unsigned char | Misc/LazySingleton.h | ||
| Ptr | T * | Misc/LazySingleton.h |
Functions
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static T & Get () |
Creates singleton once on first call. | Misc/LazySingleton.h | |
static TLazySingleton & GetLazy
(
void(*)(void*) Constructor |
Misc/LazySingleton.h | ||
static void TearDown() |
Destroys singleton. No thread must access the singleton during or after this call. | Misc/LazySingleton.h | |
static T * TryGet() |
Get or create singleton unless it's torn down | Misc/LazySingleton.h |