Replies: 3 comments
-
You could create an autorun that reads it instead? That gives an dispose
hook
…On Fri, 27 Oct 2023, 01:27 David Davidović, ***@***.***> wrote:
Currently, there seems to be no way to "dispose" of a computed value that
has been initialized with keepAlive. What I'm looking for is a way to
allow the computed to be forgotten if it's no longer being observed.
The closest I've come to is this:
computed.keepAlive_ = false;computed.suspend_();
However this is obviously not ideal because it relies on methods which are
not made available on IComputedValue<T> (for good reason).
My motivation at the moment is caching the latest invocation of a very
costly function longer than it's observed, which I do by wrapping it in a
computed with keepAlive: true. When the function gets called with
different arguments than the cached value however, I would like to forget
the old computed and create a new one for the new set of arguments.
Without being able to un-keepAlive these reactions, this would cause a
memory leak, since the old computeds will stay in memory.
—
Reply to this email directly, view it on GitHub
<#3784>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBCC4QUDHN2DTPCBLSDYBLWW3AVCNFSM6AAAAAA6R65XDGVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZVG44DEMJYHE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
True, but that would cause the |
Beta Was this translation helpful? Give feedback.
-
Sorry, meant Reaction. Track the dependency once, but never reexecute it
should do the trick. (autorun with custom scheduler that never runs again
probably does the same, not sure from top of my head)
…On Tue, 31 Oct 2023, 19:21 David Davidović, ***@***.***> wrote:
You could create an autorun that reads it instead? That gives an dispose
hook
True, but that would cause the computed to be eagerly re-evaluated
whenever the values it's observing change, which is not preferable because
we have quite a few of those. For example, in the caching scenario I
mentioned, the autorun approach would cause the old cached computed to be
reevaluated before we get a chance to see if we'll reuse it or would need
to dispose it. If the latter, we'd effecitvely be throwing away that
computation.
—
Reply to this email directly, view it on GitHub
<#3784 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBFAZJTNGW4Q6PXUTLLYCE6SBAVCNFSM6AAAAAA6R65XDGVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TIMZYGQYDC>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Currently, there seems to be no way to "dispose" of a computed value that has been initialized with
keepAlive
. What I'm looking for is a way to allow thecomputed
to be forgotten if it's no longer being observed.The closest I've come to is this:
However this is obviously not ideal because it relies on methods which are not made available on
IComputedValue<T>
(for good reason).My motivation at the moment is caching the latest invocation of a very costly function longer than it's observed, which I do by wrapping it in a
computed
withkeepAlive: true
. When the function gets called with different arguments than the cached value however, I would like to forget the oldcomputed
and create a new one for the new set of arguments. Without being able to un-keepAlive these reactions, this would cause a memory leak, since the oldcomputed
s will stay in memory.Beta Was this translation helpful? Give feedback.
All reactions