TObjectPtr
UE's TObjectPtr: behaves like a plain T* in every read, but every STORE shades the new referent through the incremental GC's write barrier — a mid-mark assignment can no longer hide a white object behind an already-black owner. It does NOT root; reachability comes from the owner's MPROPERTY trace, exactly like a raw pointer. A traced one whose target is destroyed (pending kill) is nulled by the next mark, before the sweep frees the target; an untraced one (a local, a member that is not an MPROPERTY) is not, which is what TWeakObjectPtr is for.
- Module
- Core
- Header
#include "Core/TObjectPtr.h"- Namespace
Mowo- Template
template<typename T>
The incremental GC (mowo.GC.Incremental) is only sound over object graphs whose MPROPERTY edges are barriered — migrate a class's raw MPROPERTY pointers to TObjectPtr before budget-marking worlds built from it. Codegen needs no changes: the CollectReference overload set traces it, and sizeof(TObjectPtr<T>) == sizeof(T*).
Constructors
| Signature | Name | Description |
|---|---|---|
constexpr TObjectPtr() = default | TObjectPtr | |
TObjectPtr(T* ptr) | TObjectPtr | |
TObjectPtr(const TObjectPtr& other) | TObjectPtr |
Public functions
| Returns | Name | Description |
|---|---|---|
TObjectPtr& | operator= | |
TObjectPtr& | operator= | |
T* | Get | |
T* | operator-> | |
T& | operator* | |
operatorT* | ||
operatorbool | ||
void | ClearGarbageReference | The GC's own write, during a mark: drops a reference whose target is pending kill (destroyed, or purged by its module's unload), so nothing points at it once the sweep frees it. |
Function details
TObjectPtr
constexpr TObjectPtr() = defaultTObjectPtr
TObjectPtr(T* ptr)TObjectPtr
TObjectPtr(const TObjectPtr& other)operator=
TObjectPtr& operator=(T* ptr)operator=
TObjectPtr& operator=(const TObjectPtr& other)Get
T* Get() const noexceptoperator->
T* operator->() const noexceptoperator*
T& operator*() const noexceptoperatorT*
operator T*() const noexceptoperatorbool
explicit operator bool() const noexceptClearGarbageReference
void ClearGarbageReference() noexceptThe GC's own write, during a mark: drops a reference whose target is pending kill (destroyed, or purged by its module's unload), so nothing points at it once the sweep frees it. Unbarriered on purpose — it stores null.