Skip to content

fix: memory cycle in diverts#23

Open
brentjanderson wants to merge 1 commit into
bladecoder:mainfrom
brentjanderson:fix-reference-cycle-leak
Open

fix: memory cycle in diverts#23
brentjanderson wants to merge 1 commit into
bladecoder:mainfrom
brentjanderson:fix-reference-cycle-leak

Conversation

@brentjanderson

@brentjanderson brentjanderson commented Mar 26, 2026

Copy link
Copy Markdown

There is an Rc<T> cycle between a Container, a Divert, back to a Container. This reliably produces a memory leak when running multiple stories in sequence or parallel (memory_leak_test helps verify this).

By caching potential targets and using Weak<T> to break the cycle, we avoid this memory leak case.

This shouldn't change the performance profile of a running story, as target references are already lazily loaded. We are just moving from the Divert struct to a shared cache with weak references.

There is an Rc<T> cycle between a Container, a Divert, back to a Container. This reliably produces a memory leak when running multiple stories in parallel (memory_leak_test covers this case).

By caching potential targets and using Weak<T> to break the cycle, we avoid this memory leak case.

This shouldn't change the performance profile of a running story, as target references are already lazily loaded. We are just moving from the Divert struct to a shared cache with weak references.
@brentjanderson brentjanderson force-pushed the fix-reference-cycle-leak branch from 69e07cd to 6260147 Compare March 26, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant