<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/garbage-collection-without-unsafe-code-wyvcimhk7" -->

---
title: Garbage Collection Without Unsafe Code | daily.dev
description: The author presents safe-gc, a Rust garbage collection library implemented entirely without unsafe code — no unsafe in the API, no unsafe in the...
canonical: https://daily.dev/posts/garbage-collection-without-unsafe-code-wyvcimhk7
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Garbage Collection Without Unsafe Code | daily.dev
og:description: The author presents safe-gc, a Rust garbage collection library implemented entirely without unsafe code — no unsafe in the API, no unsafe in the...
og:url: https://daily.dev/posts/garbage-collection-without-unsafe-code-wyvcimhk7
og:image: https://api.daily.dev/og/posts/WyvciMHK7.png
og:image:alt: Garbage Collection Without Unsafe Code
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Garbage Collection Without Unsafe Code

**[Hacker News](https://daily.dev/sources/hn)** · 18 min read · 0 upvotes · 0 comments

## Summary

The author presents safe-gc, a Rust garbage collection library implemented entirely without unsafe code — no unsafe in the API, no unsafe in the implementation, enforced via forbid(unsafe_code). The library uses a mark-and-sweep algorithm with arenas backed by Vec, indexed via Gc<T> and Root<T> types rather than direct pointer derefs, which is the key design choice enabling safe Rust compliance. The post explains the heap structure, root set management, the two-level mark stack for heterogeneous types, and how classic GC footguns like dangling references and finalizer misuse are downgraded from memory-safety violations to ordinary bugs. The author also details a failed attempt at implementing a copying collector in safe Rust, explaining why heterogeneous heap types make forwarding pointers difficult to express within Rust's borrow checker.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://fitzgen.com/2024/02/06/safe-gc.html>

## Similar posts on daily.dev

- [kyju.org](https://daily.dev/posts/kyju-org-cwlzepurv) · Lobsters · 0 upvotes · 0 comments
- [Rust Ownership Under the Hood: How Rust Manages Memory Without a Garbage Collector](https://daily.dev/posts/rust-ownership-under-the-hood-how-rust-manages-memory-without-a-garbage-collector-iwyribsvw) · Medium · 0 upvotes · 0 comments
- [kyju.org](https://daily.dev/posts/kyju-org-xxojlpqml) · Lobsters · 0 upvotes · 0 comments
- [Garbage collection in Rust got a little better](https://daily.dev/posts/garbage-collection-in-rust-got-a-little-better-zximifcs8) · Lobsters · 16 upvotes · 3 comments

---

Tags: [#rust](https://daily.dev/tags/rust)

[View this post on daily.dev](https://daily.dev/posts/garbage-collection-without-unsafe-code-wyvcimhk7)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Garbage Collection Without Unsafe Code","url":"https://daily.dev/posts/garbage-collection-without-unsafe-code-wyvcimhk7","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/garbage-collection-without-unsafe-code-wyvcimhk7"},"datePublished":"2026-04-22T14:57:37.804Z","dateModified":"2026-04-22T14:58:02.346Z","description":"The author presents safe-gc, a Rust garbage collection library implemented entirely without unsafe code — no unsafe in the API, no unsafe in the...","image":"https://media.daily.dev/image/upload/s--VDukGCjf--/f_auto/v1722860399/public/Placeholder%2002","thumbnailUrl":"https://media.daily.dev/image/upload/s--VDukGCjf--/f_auto/v1722860399/public/Placeholder%2002","isAccessibleForFree":true,"articleSection":"Hacker News","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Hacker News","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/hn","url":"https://daily.dev/sources/hn"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/garbage-collection-without-unsafe-code-wyvcimhk7","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"rust","timeRequired":"PT18M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Hacker News","item":"https://daily.dev/sources/hn"},{"@type":"ListItem","position":3,"name":"Garbage Collection Without Unsafe Code"}]}
```

