Flashcard Deck · 21 cards · Public

Rust Programming - Ownership, Borrowing & Memory Safety

Master Rust's core paradigms including ownership, borrowing rules, lifetimes, smart pointers, and zero-cost abstractions with this comprehensive flashcard deck.

Cards in this deck

(21 cards)

Preview terms and definitions before starting your study session.

#1
Term
What is Rc<T> and when should it be used?
Definition
Rc<T> (Reference Counted) enables multiple ownership of immutable data in single-threaded scenarios. It keeps track of active references and deallocates memory when the reference count drops to zero.
#2
Term
What is Arc<T> and how does it differ from Rc<T>?
Definition
Arc<T> (Atomically Reference Counted) provides thread-safe shared ownership across multiple threads using atomic operations for counting. It incurs a minor runtime overhead compared to non-thread-safe Rc<T>.
#3
Term
What are the Three Rules of Ownership in Rust?
Definition
1. Each value in Rust has an owner (a variable).
2. There can only be one owner at a time.
3. When the owner goes out of scope, the value is automatically dropped (deallocated).
#4
Term
What are Move Semantics in Rust?
Definition
When a stack variable pointing to heap memory is assigned to another variable or passed into a function, ownership is transferred ("moved"). The original variable becomes invalid, preventing double-free memory bugs.
#5
Term
How do the Copy and Clone traits differ in Rust?
Definition
Copy performs an implicit, low-cost bitwise copy for stack-only data types (e.g., i32, bool). Clone requires an explicit call (.clone()) to perform a deep copy of heap-allocated resources.
#6
Term
What are the fundamental rules of Borrowing (&T vs &mut T)?
Definition
At any given point in a scope, you can have either:
  • Any number of immutable references (&T), OR
  • Exactly one mutable reference (&mut T).
References must always be valid and cannot outlive the underlying data.
#7
Term
What is a Dangling Reference, and how does Rust prevent it?
Definition
A dangling reference points to a memory location that has already been deallocated. Rust's borrow checker prevents dangling references at compile time by ensuring all references stay within their valid lifetimes.
#8
Term
What is RAII (Resource Acquisition Is Initialization) in Rust?
Definition
RAII ties resource management (memory, file handles, sockets) to an object's lifetime. When an object goes out of scope, Rust automatically invokes its Drop::drop implementation to free resources.
Showing 8 of 21 cards in this deck.
Study All Now

Related Flashcard Sets

Explore similar study materials created by the community

Browse community decks