UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TLazySingleton< T > Class Template Referencefinal

#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)
 

Detailed Description

template<class T>
class TLazySingleton< T >

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(); }

Member Function Documentation

◆ Get()

template<class T >
static T & TLazySingleton< T >::Get ( )
inlinestatic

Creates singleton once on first call. Thread-safe w.r.t. other Get() calls. Do not call after TearDown().

◆ TearDown()

template<class T >
static void TLazySingleton< T >::TearDown ( )
inlinestatic

Destroys singleton. No thread must access the singleton during or after this call.

◆ TryGet()

template<class T >
static T * TLazySingleton< T >::TryGet ( )
inlinestatic

Get or create singleton unless it's torn down


The documentation for this class was generated from the following file: