3 ms·
"I’m not sure what this pattern is called in Java, but in JavaScript it’s called a ‘memory leak’." The comment is in regards to goog.memoize but is terribly ba
by kwamenum86 16y ago
"I’m not sure what this pattern is called in Java, but in JavaScript it’s called a ‘memory leak’."
The comment is in regards to goog.memoize but is terribly backwards. The complaint about goog.memoize is that it will grow uncontrollably because it does not cap the size of the caching object. A memory leak is the inability of a program to free memory it has allocated.
Since js is garbage collected causing a memory leak involves creating a circular reference fooling the garbage collector into thinking that an object is still in use.
- ivank 16y ago> A memory leak is the inability of a program to free memory it has allocated. Unexpected memoization/caching also counts as a memory leak. There are (unfortunately) a few places in Closure Library where unexpected memoization might cause a memory leak. > Since js is garbage collected causing a memory leak involves creating a circular reference fooling the garbage collector into thinking that an object is still in use. Browser environments are expected to handle circular references. They don't fool garbage collectors, except in old versions of IE when a circular reference crosses the JScript/DOM boundary.
- kwamenum86 16y agoAre you saying that the memory allocated by the memoizer is not recoverable e.g. won't be released until the browser is killed? If not then it is not a memory leak.
- ivank 16y agoIt's potentially recoverable, but stuck in some "private" object your JavaScript application will never bother to look at. It's still a memory leak.
- deleted 16y ago[deleted]