RealDocs

TSharedPtr::Reset

function Core Since 4.0
#include "Templates/SharedPointer.h"
Access: public Specifiers: inline

Description

Releases this shared pointer's reference to the managed object. If this was the last shared reference the object is destroyed. After the call the pointer is null and IsValid() returns false.

Caveats & Gotchas

  • Reset() is implemented as assignment from a default-constructed TSharedPtr (i.e. *this = TSharedPtr<ObjectType>()). This means it goes through the normal copy assignment path and its cost includes a reference-count decrement and a potential deallocation.
  • Assigning nullptr to a TSharedPtr (ptr = nullptr) also calls Reset() implicitly via the operator=(FNullTag*) overload. The two forms are equivalent.
  • If the object was created with a custom deleter via MakeShareable(ptr, deleter), Reset() will invoke that deleter rather than the default delete.

Signature

UE_FORCEINLINE_HINT void Reset()

Return Type

void

Example

Releasing ownership C++
TSharedPtr<FMyData> DataPtr = MakeShared<FMyData>();
check(DataPtr.IsValid());

DataPtr.Reset();
check(!DataPtr.IsValid()); // DataPtr is now null

// Equivalent:
DataPtr = nullptr;

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.