Last active
January 4, 2020 15:17
-
-
Save YonatanKra/3e62efebab93b8e84c06fa0ea9891a54 to your computer and use it in GitHub Desktop.
A code that creates a lot of garbage collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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