1
00:00:02,320 --> 00:00:05,860
Now one word about memory consumption and memory usage.

2
00:00:05,890 --> 00:00:14,200
If every function logs in all surrounding variables, doesn't that lead to a pretty bad effect in our

3
00:00:14,200 --> 00:00:20,830
memory because in big applications where we have many variables, a function might log in a lot of variables

4
00:00:20,860 --> 00:00:22,630
which it never uses.

5
00:00:22,690 --> 00:00:30,490
So Javascript doesn't get rid of these variables because a function closed over them but the function

6
00:00:30,490 --> 00:00:35,750
might never get called or even if it gets called, it might not be interested in all variables,

7
00:00:35,770 --> 00:00:37,920
so isn't that a memory issue?

8
00:00:37,960 --> 00:00:43,900
In theory, it would be but of course Javascript engines are pretty smart or the people who are working

9
00:00:43,900 --> 00:00:49,990
on them are pretty smart and therefore, modern Javascript engines optimize this.

10
00:00:49,990 --> 00:00:56,290
They basically track variable usage you could say and if a variable obviously isn't getting used

11
00:00:56,290 --> 00:01:03,460
by anything, not by any functions and nowhere else, then they will get rid of it and they will do so of

12
00:01:03,460 --> 00:01:08,680
course in a safe way so that they don't accidentally crash your program because you need to use that

13
00:01:08,680 --> 00:01:10,260
function at some point of time,

14
00:01:10,330 --> 00:01:15,250
they're really smart about that and they optimize this whole behavior so that you don't manually have

15
00:01:15,250 --> 00:01:21,510
to reset all variables that you don't need, Javascript engines will do that for you in a smart way.
