memory-and-gc
Installation
SKILL.md
Memory & garbage collection
Unreal has two memory worlds: garbage-collected UObjects managed by the engine's GC, and
ordinary C++ heap objects you manage with smart pointers or RAII. Mixing them up causes most UE
crashes. The one rule that prevents the majority of them: a UObject stays alive only while
something reachable from the root set holds it in a UPROPERTY (or an equivalent GC-tracked
reference).
When to use this skill
- Choosing which pointer type to use for a UObject or plain C++ object.
- Crash after a few seconds or after a level load — the classic "GC collected it" symptom.
- A non-UObject class (subsystem helper, Slate widget, RAII guard) needs to keep a UObject alive.
- "Why is my pointer suddenly null or garbage?" debugging.
- Deciding between
TSharedPtr,TSharedRef,TUniquePtr, orFGCObjectfor a new type.
See also: cpp-fundamentals for UObject/UPROPERTY/UFUNCTION macro basics; actors-and-components
for actor ownership and component lifetime.