alexcrichton opened PR #2017 from fix-leak to main:
This commit fixes a memory leak that can happen with
Linker::module
when the provided module is a command. This function creates a closure
but the closure closed over a strong reference toStore(and
transitively through any imports provided). Unfortunately aStore
keeps everything alive, includingFunc, so this meant thatStorewas
inserted into a cycle which caused the leak.The cycle here is manually broken with
Weak<StoreInner>, which needs
to be plumbed through for allExternitems as well.
alexcrichton requested sunfishcode for a review on PR #2017.
sunfishcode submitted PR Review.
sunfishcode created PR Review Comment:
It's not immediately clear to me how this fixes the cycle.
Funcalso contains a strongStoreInstanceHandleandInstancecontains a strongStore, so is there already a cycle?
alexcrichton submitted PR Review.
alexcrichton created PR Review Comment:
The problem here is that a strong reference to
Storewas closed over in theFunc, which meant thatStorebasically had a strong reference to itself. By only closing over weak references that reference is broken at least. Each of the captures here only capture a weak version of theStoreor external item.
alexcrichton updated PR #2017 from fix-leak to main:
This commit fixes a memory leak that can happen with
Linker::module
when the provided module is a command. This function creates a closure
but the closure closed over a strong reference toStore(and
transitively through any imports provided). Unfortunately aStore
keeps everything alive, includingFunc, so this meant thatStorewas
inserted into a cycle which caused the leak.The cycle here is manually broken with
Weak<StoreInner>, which needs
to be plumbed through for allExternitems as well.
alexcrichton edited PR #2017 from fix-leak to main:
This commit fixes a memory leak that can happen with
Linker::module
when the provided module is a command. This function creates a closure
but the closure closed over a strong reference toStore(and
transitively through any imports provided). Unfortunately aStore
keeps everything alive, includingFunc, so this meant thatStorewas
inserted into a cycle which caused the leak.The cycle here is manually broken by closing over the raw value of each
external value rather than the external value itself (which has a
strong reference toStore).
peterhuene submitted PR Review.
alexcrichton merged PR #2017.
Last updated: Dec 06 2025 at 06:05 UTC