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); }