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 thatStore
was
inserted into a cycle which caused the leak.The cycle here is manually broken with
Weak<StoreInner>
, which needs
to be plumbed through for allExtern
items 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.
Func
also contains a strongStoreInstanceHandle
andInstance
contains 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
Store
was closed over in theFunc
, which meant thatStore
basically 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 theStore
or 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 thatStore
was
inserted into a cycle which caused the leak.The cycle here is manually broken with
Weak<StoreInner>
, which needs
to be plumbed through for allExtern
items 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 thatStore
was
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: Nov 22 2024 at 16:03 UTC