Every value in Rust has exactly one owner. When the owner goes out of scope, the value is dropped.
let s1 = String::from("hello");
let s2 = s1; // s1 is MOVED into s2
// println!("{s1}"); // ERROR: s1 is no longer valid
println!("{s2}"); // OK
Unlike garbage-collected languages, Rust doesn't copy heap data by default. Assignment moves ownership.
i32, bool, f64) implement Copy β assignment copies the bitsString, Vec<T>) are moved β only the pointer is copied, original is invalidatedClone TraitTo explicitly duplicate heap data:
let s1 = String::from("hello");
let s2 = s1.clone(); // deep copy
println!("{s1} {s2}"); // both valid
Solana programs are written in Rust. Understanding ownership prevents common bugs like use-after-free and double-free β without needing a garbage collector eating into your compute units.