Skip to content

Commit 713afa9

Browse files
authored
Clarify that clearInterval is needed
Clearing an interval, other than reloading the browser/process, is the only way to garbage-collect a set interval, so it would stop running.
1 parent 2c75b95 commit 713afa9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3685,7 +3685,11 @@ config = null;
36853685

36863686
#### Answer: C
36873687

3688-
Normally when we set objects equal to `null`, those objects get _garbage collected_ as there is no reference anymore to that object. However, since the callback function within `setInterval` is an arrow function (thus bound to the `config` object), the callback function still holds a reference to the `config` object. As long as there is a reference, the object won't get garbage collected. Since it's not garbage collected, the `setInterval` callback function will still get invoked every 1000ms (1s).
3688+
Normally when we set objects equal to `null`, those objects get _garbage collected_ as there is no reference anymore to that object. However, since the callback function within `setInterval` is an arrow function (thus bound to the `config` object), the callback function still holds a reference to the `config` object.
3689+
As long as there is a reference, the object won't get garbage collected.
3690+
Since this is an interval, setting `config` to `null` or `delete`-ing `config.alert` won't garbage-collect the interval, so the interval will still be called.
3691+
It should be cleared with `clearInterval(config.alert)` to remove it from memory.
3692+
Since it was not cleared, the `setInterval` callback function will still get invoked every 1000ms (1s).
36893693

36903694
</p>
36913695
</details>

0 commit comments

Comments
 (0)