Superteam Academy
|bySuperteam BrasilSuperteam Brasil
Superteam Academy

The decentralized learning platform for Solana developers.

Resources

  • Courses
  • Leaderboard
  • Community

Support

  • Documentation
  • API Reference
  • Community

Legal

  • Terms of Service
  • Privacy Policy
  • Cookie Policy

Follow Us

  • Twitter / X
  • Discord
  • GitHub

Stay in the Loop

Get weekly updates on new courses, Solana ecosystem news, and learning tips.

Powered bySuperteam BrasilSuperteam Brasil

Β© 2026 Superteam Academy. All rights reserved.

Rust Ownership & Memory

How Ownership Works

Ownership Fundamentals / How Ownership Works
30 XP

How Ownership Works

Ownership in Rust

Every value in Rust has exactly one owner. When the owner goes out of scope, the value is dropped.

The Three Rules

  1. Each value has a single owner variable
  2. There can only be one owner at a time
  3. When the owner goes out of scope, the value is dropped

Move Semantics

Rust
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.

Stack vs. Heap

  • Stack types (i32, bool, f64) implement Copy β€” assignment copies the bits
  • Heap types (String, Vec<T>) are moved β€” only the pointer is copied, original is invalidated

The Clone Trait

To explicitly duplicate heap data:

Rust
let s1 = String::from("hello");
let s2 = s1.clone(); // deep copy
println!("{s1} {s2}"); // both valid

Why This Matters for Solana

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.

You need to enroll in this course before you can mark lessons as complete.
1 / 3