Description
Marks this UObject to be destroyed by the garbage collector on the next GC pass. After calling this, `IsValid()` returns false. Use this instead of `delete` to destroy UObjects.
Signature
void MarkAsGarbage() Return Type
void Caveats & Gotchas
- • Previously named `MarkPendingKill()` which was deprecated in UE 5.0.
- • The object is not immediately destroyed — it persists until the GC runs.
- • AActor subclasses should prefer `Destroy()` which also handles actor lifecycle cleanup.
Example
Disposing a UObject C++
UMyObject* Obj = NewObject<UMyObject>(this);
// ... use Obj ...
Obj->MarkAsGarbage(); // Schedule for GC
// IsValid(Obj) now returns false See Also
Version History
Introduced in: 5.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
| 5.0 | stable | Replaces deprecated MarkPendingKill(). |
Feedback
Was this helpful?