Yomguithereal / baobab

JavaScript & TypeScript persistent and optionally immutable data tree with cursors.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question regarding releasing cursors

soulprovidr opened this issue · comments

Hi, I have a question about cursors and potential memory leaks arising from their use.

In our application we have a lot of modules that look like this:

export default function setDeeplyNestedProperty(tree, value) {
    const shortcutCursor = tree.select(['foo', 'bar', 'baz']);
    const newValue = doSomeCalculationOrTransformation(value);
    shortcutCursor.set(newValue);
}

My question is, will using .select() in this fashion cause a memory leak? Should we call shortcutCursor.release() at the end of the function? (That's what the docs seem to suggest).

Thanks!

Normally, if I remember correctly how I implemented the library, if you don't set listeners on said cursors, you won't leak memory. What's more, cursors are memoized, meaning that if you select multiple times the same cursor, the same object will be returned. But if you want to be sure, using release should be safe.

Thanks, good to know!