Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active January 4, 2020 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonatanKra/3e62efebab93b8e84c06fa0ea9891a54 to your computer and use it in GitHub Desktop.
Save YonatanKra/3e62efebab93b8e84c06fa0ea9891a54 to your computer and use it in GitHub Desktop.
A code that creates a lot of garbage collection
class Demo {
constructor(counter) {
this.counter = counter;
}
setMe() {
this.counter.count += 1;
}
}
function createAndCount() {
const objs = [];
const counter = {
count: 0
};
for (let i = 0; i < 1000; i++) {
for (let demo = 0; demo < 1000; demo++) {
const currBoom = objs[objs.push(new Demo(counter)) - 1];
currBoom.setMe();
}
objs.length = 0;
}
console.log(`Counter is: ${counter.count}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment