I built a garbage collector for Rust (2023)
Web page · https://claytonwramsey.com/blog/dumpster
First seen by Oriel on .
AI summary
This article explains how the author built dumpster, a cycle-detecting garbage collector for Rust despite Rust lacking facilities for transparently tracing arbitrary allocations.
- dumpster provides a Gc API modeled after Rc and Arc, but requires contained types to implement the Collectable trait.
- A Visitor implementation exposes outgoing Gc references, allowing reachability analysis over an allocation graph without scanning the stack.
- The collector handles cycles by identifying inaccessible subgraphs, then bulk-drops allocations to avoid quadratic cleanup caused by recursive Drop calls.
- A dumpster stores potentially unreachable allocations and periodically collects them, making reference operations average-case O(1) rather than immediately traversing the graph.
- Supporting ?Sized values and runtime type erasure requires separate thin allocation identifiers, reconstructible fat pointers, and opaque type-specific function pointers.
#rust #garbage collection #memory management #reference counting
Generated by gpt-5.6-sol. Check the original for details.
Metric trends
Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained
Points
Score reported by the source.
- Lobsters: 19, latest observation ; +18 over observed period since
Comments
Comment count reported by the source.
- Lobsters: 9, latest observation ; +9 over observed period since
Aliases
| Source | External ID | URL |
|---|---|---|
| Lobsters | ju4q1u | https://claytonwramsey.com/blog/dumpster/ Read discussion |