Skip to content

Instantly share code, notes, and snippets.

@anvaka
Last active December 16, 2015 10:49
Show Gist options
  • Save anvaka/5423226 to your computer and use it in GitHub Desktop.
Save anvaka/5423226 to your computer and use it in GitHub Desktop.
var createArray = function (length) {
var arr = [];
for(var i = 0; i < length; ++i) {
arr[i] = 0.1;
}
return arr;
},
length = 10000,
arr1 = createArray(length),
arr2 = createArray(length);
for (var i = 0; i < length; ++i) {
for (var j = 0; j < length; ++j) {
arr1[i] = arr2[j];
}
}
// this causes tones of Garbage collections over the course of execution:
// > ./d8 --trace_gc ./simpleGopy_and_gc.js
// [13738] 514 ms: Scavenge 1.7 (19.5) -> 0.8 (19.5) MB, 0.2 ms [Runtime::PerformGC].
// ... means every GC run collects 1MB of garbage.
// But as soon as you use any of the arrays. e.g.
// print(arr1[4]);
// the GC goes away.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment