---
source: https://iinventedlight.com/library/notes/rust-reference-cycles.md
title: "Reference cycles in Rust: leaks and Weak pointers"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (The Rust Programming Language); MIT OR Apache-2.0 (Rust Standard Library); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Reference Cycles Can Leak Memory; Rust Standard Library, std::rc::Weak. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust/master/COPYRIGHT). Copyright the Rust Project Developers."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: rust-reference-cycles"
tags: [rust, rc, weak, reference-cycle, memory]
client: Librarian
sources:
  - id: S1
    title: "Reference Cycles Can Leak Memory"
    publisher: The Rust Programming Language
    url: https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "std::rc::Weak"
    publisher: Rust Standard Library
    url: https://doc.rust-lang.org/std/rc/struct.Weak.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
---
# Reference cycles in Rust: leaks and Weak pointers
**Answer:** Rust makes accidental memory leaks difficult, but not impossible. An Rc value is only cleaned up when its strong_count is 0, so a cycle of strong references can leak. Weak holds a non-owning reference and can be upgraded later.

## How a cycle can leak

Rust's memory safety guarantees make leaks difficult, but not impossible.

It is still possible to accidentally create memory that is never cleaned up, known as a memory leak.

Calling Rc::clone increases the strong_count of an Rc instance.

An Rc instance is only cleaned up if its strong_count is 0.

You can prevent reference cycles by using Weak.

## What Weak holds

Weak holds a non-owning reference to the managed allocation.

Call upgrade when you need access to that allocation.

upgrade returns an Option of Rc.

Because a Weak reference does not count towards ownership, it will not prevent the inner value from being dropped.

## See also

- [rust-rc-refcell](https://iinventedlight.com/library/notes/rust-rc-refcell/)
- [rust-drop](https://iinventedlight.com/library/notes/rust-drop/)

## Claims

- id: C1
  claim: Memory safety makes leaks difficult, but not impossible.
  source: S1
  evidence: "difficult, but not impossible"

- id: C2
  claim: An Rc instance is only cleaned up if its strong_count is 0.
  source: S1
  evidence: "only cleaned up if its strong_count is 0"

- id: C3
  claim: Weak holds a non-owning reference to the managed allocation.
  source: S2
  evidence: "non-owning reference to the managed allocation"

- id: C4
  claim: upgrade on a Weak pointer returns an Option of Rc.
  source: S2
  evidence: "returns an Option"

## Sources

- [S1] Reference Cycles Can Leak Memory. The Rust Programming Language. https://doc.rust-lang.org/book/ch15-06-reference-cycles.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.

- [S2] std::rc::Weak. Rust Standard Library. https://doc.rust-lang.org/std/rc/struct.Weak.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Reference Cycles Can Leak Memory; Rust Standard Library, std::rc::Weak. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust/master/COPYRIGHT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
