nano-memoize icon indicating copy to clipboard operation
nano-memoize copied to clipboard

Timeout Leak from `d` function

Open kerrigan-nm opened this issue 1 year ago • 1 comments

Since the d function reassigns the value of the to timeout variable on each call, only the last timeout created is ever available in scope. This means that when the clear function clears the timeout, it is only ever clearing the most recently created timeout.

Basically, if maxAge is set, a new timeout is created every time a memoized function is called with a new set of arguments, and all but the last timeout created are unable to be cleared. This holds the node process open until those timeouts complete, even if .clear() is called on the memoized function.

kerrigan-nm avatar Jun 27 '24 22:06 kerrigan-nm

@kerrigan-nm It there a reason you opened and then closed this request? Did you determine a leak was not actually happening?

Also, it has been a long time since I was in this code. Would it be better to check and see if to is non-nul and then just clear it before setting a new timeout rather than keep a Set around.

anywhichway avatar Jul 02 '24 00:07 anywhichway