Comment

Comment by danielnaab

I've used a WeakMap for a kind of memoization.

Assume an immutable object may undergo an expensive transform that returns an object, which is then stored in a WeakMap keyed to the immutable. When there are no new references to that object, the garbage collector will clean it up, but otherwise the expensive transform may be avoided with a lookup on the WeakMap.

It provides a pretty nice way to decouple your caching from the rest of the codebase.

parent danielnaab 11 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton