TSharedRef::SharedReferenceCount
#include "Templates/SharedPointer.h"
Access: private
Description
The reference-counter handle shared with all TSharedPtr and TSharedRef instances that co-own the same object. Manages object lifetime and exposes the count via the public GetSharedReferenceCount() method.
Caveats & Gotchas
- • SharedReferenceCount is private. Call GetSharedReferenceCount() for the count — and only for debugging, as it is documented as not necessarily fast.
- • TSharedRef guarantees at least one live shared reference exists at all times, so GetSharedReferenceCount() on a TSharedRef always returns >= 1, unlike TSharedPtr which can be null with count 0.
- • The reference controller is shared with any TWeakPtr pointing to the same object. It is freed only when both the shared count and weak count reach zero — holding weak pointers prevents controller deallocation.
Signature
SharedPointerInternals::FSharedReferencer< Mode > SharedReferenceCount Example
Observing reference count across TSharedRef and TSharedPtr C++
TSharedRef<FMyData> Ref1 = MakeShared<FMyData>();
TSharedRef<FMyData> Ref2 = Ref1; // count = 2
TSharedPtr<FMyData> Ptr = Ref1; // count = 3
UE_LOG(LogTemp, Log, TEXT("%d"), Ref1.GetSharedReferenceCount()); // 3 Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?