TreeviewCopyright © aleen42 all right reserved, powered by aleen42

Six Months in a Leaky Boat Back

Problem

/* from Google Closure 
 * from memoize.js, Line 39
 * 雖然Google Closure採用了Cache來緩存執行結果以提高執行效率. 但是, 並沒有提供任何
 * 方法來限制緩存的大小, 這在JavaScript將導致Memory Leak
*/
goog.memoize = function(f, opt_serializer) {
  var functionHash = goog.getHashCode(f);
  var serializer = opt_serializer || goog.memoize.simpleSerializer;

  return function() {
    // Maps the serialized list of args to the corresponding return value.
    var cache = this[goog.memoize.CACHE_PROPERTY_];
    if (!cache) {
      cache = this[goog.memoize.CACHE_PROPERTY_] = {};
    }
    var key = serializer(functionHash, arguments);
    if (!(key in cache)) {
      cache[key] = f.apply(this, arguments);
    }
    return cache[key];
  };
};
Empty Comments
Sign in GitHub

As the plugin is integrated with a code management system like GitLab or GitHub, you may have to auth with your account before leaving comments around this article.

Notice: This plugin has used Cookie to store your token with an expiration.