5 ms·
I was debugging my apps monstrous memory leak. It took me quite a while to figure out that ‘useMemo’ was sneakily responsible for it. Currently the way this hoo
by kushan2020 5y ago
I was debugging my apps monstrous memory leak. It took me quite a while to figure out that ‘useMemo’ was sneakily responsible for it. Currently the way this hook works is that it will hold references to all the objects that go through it. In most cases these objects are pretty small and trivially contribute to a leak, but in my case I was saving a giant class instance which was causing significant memory usage.
Just wanted to share this on how the simple looking hooks can hide some really hard to find bugs.
- jitl 5y agoDo you mean that it holds references to all versions of the memo’s dependency array AND all versions of the memo return value, or just that it holds the last version?
- kushan2020 5y agoIt holds all of the references to the dependencies strongly, which makes sense since it is a memorization helper function. It saves all the dependencies to avoid recomputing if the same dependency shows up any time in future. But in my case I was using an old school library where you call destroy and set reference to the instance as null, and putting that as a dependency in usMemo was a bad idea.