I want to be able to keep track of how many arrays a certain program uses, so that I can figure out if unnecessary memory has been allocated.The problem I am running into is Javascript's construct that array literal []
does not trigger Array#constructor
. Is there another way for me to keep track of array usage? ES5 and/or ES6 and beyond.
var arrayConstructor = Array // store reference
window.arrCount = 0
window.Array = function() {
arrCount++;
return new Array();
}
var arr1 = new Array
window.arrCount // 1
var arr2 = []
window.arrCount // 1 : NOT WORKING!