DEV Community

Discussion on: Memoization in Javascript

Collapse
gerardolima profile image
Gerardo Lima • Edited on

I'd recommend using a Map or a WeakMap as memo, instead of object. Also, I'd recommend using some sort of lock to avoid executing the underlying "expensive" function while another instance is running for the same parameters.

Collapse
anishkumar profile image
Anish Kumar Author • Edited on

Yes. WeakMap would be a good choice if you are using objects as keys, it would facilitate better garbage collection in this case. If your keys are strings, using object should be fine.