Skip to content

Modern SharedPtr UseCount

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

Home › Smart Pointers › SharedPtr and WeakPtr › UseCount

UseCount

Returns how many SharedPtr handles share the object.

Syntax

UseCount( ) as int32

Examples

#import "std/memory"
using memory

type Node
    as int32 id
end type

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

scope
    dim q as SharedPtr( of Node ) = p      '' a second handle
    print p.UseCount( )      '' 2
end scope

'' q left scope, so its reference was dropped
print p.UseCount( )          '' 1

'' Under -mt the counts are touched through the rtlib atomics. That covers
'' the CONTROL BLOCK, never the pointee: two threads mutating the object
'' itself still need their own lock.

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

Clone this wiki locally