liveBook · Manning

Garbage collection

As explained in Rust Servers, Services, and Apps

Garbage collection is automatic reclamation of memory occupied by objects that are no longer reachable by a program.

Garbage collection automatically reclaims memory occupied by objects that are no longer reachable by a program. It reduces the risks of manual memory management, but can reduce execution speed, consume additional compute resources, and stall execution. It also manages memory only, not resources such as network sockets or database handles. section 1.2.2

Garbage collection appears as one option in a broader memory-management comparison:

  • Manual memory management, used by C and C++, provides low-level control but increases the risk of memory-related correctness errors. section 1.2.2
  • Garbage-collected languages include Java, C#, Python, Ruby, and Go, using automatic memory management to make programs safer. section 1.2.2
  • Rust takes a different approach: its ownership model provides automatic memory management and memory safety without a garbage collector. section 1.2.2
  • Rust makes ownership explicit, models resource management around RAII, and uses smart pointers for safe memory usage. section 1.2.2

How Rust Servers, Services, and Apps covers it

How deep it goes
Explains safety benefits and runtime costs, but stops short of describing garbage-collector algorithms or implementation internals.
Examples
Names Java, C#, Python, Ruby, and Go as garbage-collected languages, contrasting them with Rust, C, and C++.
What you can do after
Evaluate memory-management choices by weighing safety, performance, compute use, execution stalls, and non-memory resource handling.
How it connects
Connects garbage collection to manual memory management, memory safety, ownership, RAII, smart pointers, and resource management.

Also explained in

Compare how 9 books explain garbage collection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.