Skip to content

Commit c5c94bc

Browse files
committed
closes #1547
1 parent 7510263 commit c5c94bc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

1-js/06-advanced-functions/03-closure/article.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ function f() {
565565
*/!*
566566
}
567567

568-
let g = f(); // g is reachable, and keeps the outer lexical environment in memory
568+
let func = f(); // func gets a reference to g
569+
// so it stays and memory and its outer lexical environment stays as well
569570
```
570571

571572
Please note that if `f()` is called many times, and resulting functions are saved, then all corresponding Lexical Environment objects will also be retained in memory. All 3 of them in the code below:
@@ -595,10 +596,9 @@ function f() {
595596
return g;
596597
}
597598

598-
let g = f(); // while g is alive
599-
// their corresponding Lexical Environment lives
599+
let func = f(); // while func has a reference to g, it stays in memory
600600

601-
g = null; // ...and now the memory is cleaned up
601+
func = null; // ...and now the memory is cleaned up
602602
```
603603

604604
### Real-life optimizations

0 commit comments

Comments
 (0)