From 819f4d2151dea49f2e58eb0320d4ad16f58f579a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 3 Jun 2013 08:43:04 -0700 Subject: [PATCH] Add `maxPoolSize` to limit array and object pools. Former-commit-id: 677cdb053c7ef60274d71d9ecf4d6f866ef6a8eb --- build.js | 3 +++ lodash.js | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/build.js b/build.js index a6578fe86..47828d6eb 100755 --- a/build.js +++ b/build.js @@ -3231,6 +3231,9 @@ if (isRemoved(source, 'getObject', 'releaseObject')) { source = removeVar(source, 'objectPool'); } + if (isRemoved(source, 'releaseArray', 'releaseObject')) { + source = removeVar(source, 'maxPoolSize'); + } if (isRemoved(source, 'invert')) { source = replaceVar(source, 'htmlUnescapes', "{'&':'&','<':'<','>':'>','"':'\"',''':\"'\"}"); } diff --git a/lodash.js b/lodash.js index 9b19a747d..2cf26a5eb 100644 --- a/lodash.js +++ b/lodash.js @@ -39,6 +39,9 @@ /** Used as the size when optimizations are enabled for large arrays */ var largeArraySize = 75; + /** Used as the max size of the `arrayPool` and `objectPool` */ + var maxPoolSize = 10; + /** Used to match empty string literals in compiled template source */ var reEmptyStringLeading = /\b__p \+= '';/g, reEmptyStringMiddle = /\b(__p \+=) '' \+/g, @@ -196,6 +199,9 @@ * @param {Array} [array] The array to release. */ function releaseArray(array) { + if (arrayPool.length == maxPoolSize) { + arrayPool.length = maxPoolSize - 1; + } array.length = 0; arrayPool.push(array); } @@ -207,6 +213,9 @@ * @param {Object} [object] The object to release. */ function releaseObject(object) { + if (objectPool.length == maxPoolSize) { + objectPool.length = maxPoolSize - 1; + } object.array = object.cache = object.criteria = object.object = object.number = object.string = object.value = null; objectPool.push(object); }