Skip to content

Modern Array Shrink

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

Home › Array › Array Container › Shrink

Shrink

Releases unused room, cutting the capacity down to the count.

Syntax

Shrink( )

Notes

  • O(n) — release unused capacity

Examples

#import "std/containers"
using containers

dim v as Array( of int32 )
v.Reserve( 1000 )
v.Push( 1 ) : v.Push( 2 )

print v.Capacity         '' 1024
v.Shrink( )
print v.Capacity         '' 2 -- capacity cut down to Count

'' Shrinking an empty array releases the storage entirely
v.Clear( )
v.Shrink( )
print v.Capacity         '' 0

Library: Array Container
Category: Array
Documented under: Members

Clone this wiki locally