drop
Signature
drop(value: string): voidSignature
drop<T>(value: T[]): voiddrop(value) consumes a local string, array, collection, or native handle and releases its resources immediately. Static values need no release. The binding cannot be used afterward.
When control flow has more than one possible path, the binding is considered dropped after the branch only when every path that continues drops it. A path that ends with return or throw does not affect the availability of a sibling path that continues.
tyrus
import { drop } from "tyrus:memory";
function discard<T>(value: T[]): void {
drop(value);
}
function main(): void {
let bytes: u8[] = [1, 2, 3];
print(bytes); // [1, 2, 3]
discard(bytes);
let entries: Map<string, i32> = Map<string, i32>();
entries.set("sessions", 1);
drop(entries);
}error
tyrus
import { drop } from "tyrus:memory";
function main(): void {
let bytes: u8[] = [1, 2, 3];
drop(bytes);
print(bytes);
}text
error[E0382]: use of dropped value: `bytes`
at /src/main.tyr:6:11
print(bytes);
^^^^^
at /src/main.tyr:5:10
drop(bytes);
^^^^^ value dropped here; `bytes` cannot be used afterward
help: remove the later use of `bytes`, or move it before `drop(bytes)`