Skip to content

Modern SharedPtr Reset

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Smart Pointers › SharedPtr and WeakPtr › Reset

Reset

Drops this handle's share and leaves it null; the last one out destroys the object.

Syntax

Reset( )

Notes

  • The object is destroyed when the LAST strong handle goes away -- Reset( ) on one of several just decrements the count.
  • Afterwards IsNull is true and UseCount is 0 for this handle.
  • The same thing happens automatically at scope exit and on reassignment; Reset( ) is for releasing early.

Examples

#import "std/memory"
using memory

type Node
    as int32 id
end type

dim p as SharedPtr( of Node ) = MakeShared( of Node )( )
dim q as SharedPtr( of Node ) = p
print p.UseCount( )          '' 2

q.Reset( )                   '' drop just this handle
print p.UseCount( )          '' 1
print q.IsNull( )            '' true

p.Reset( )                   '' the last handle -- the object is destroyed now
print p.IsNull( )            '' true

Library: SharedPtr and WeakPtr
Category: Smart Pointers
Documented under: Members

Clone this wiki locally