Skip to content

Modern SharedPtr MakeShared

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

Home › Smart Pointers › SharedPtr and WeakPtr › MakeShared

MakeShared

Creates a default-constructed object and returns the first SharedPtr to it.

Syntax

MakeShared( of T )

Examples

#import "std/memory"
using memory

type Node
    as int32 id
end type

'' Allocates a default-constructed T and returns the only handle to it
dim p as SharedPtr( of Node ) = MakeShared( of Node )( )

p.Ref( ).id = 7
print p.Ref( ).id            '' 7
print p.UseCount( )          '' 1

'' The object is destroyed exactly once, when the last handle goes away --
'' no DELETE at the call site and no ownership convention to document

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

Clone this wiki locally