Some confusion of UObject*, UPROPERTY decorator, and UWeakObjectPtr

A::a isn’t exactly like a shared pointer. If all you have is two UObjects pointing at one another (UPROPERTY pointers), they’ll both get garbage collected because nothing else is referring to them. With shared_ptrs they’d both stay in memory, because they’d both have a reference count of 1.

But yeah, B:b leaves a dangling pointer. It has no effect on lifetime and won’t be nulled when the object is destroyed; it’s just a normal C++ pointer to the UObject’s location in memory, the engine doesn’t know about it.

1 Like