1
00:00:00,000 --> 00:00:03,380
What does using actually clean up?

2
00:00:03,380 --> 00:00:07,200
Does it just ask the garbage collector nicely?

3
00:00:07,380 --> 00:00:08,610
No.

4
00:00:08,610 --> 00:00:11,280
Using calls a resource’s cleanup method

5
00:00:11,280 --> 00:00:13,320
when execution leaves the block.

6
00:00:13,320 --> 00:00:15,580
That method lives under Symbol dot

7
00:00:15,580 --> 00:00:17,940
dispose, a special property key.

8
00:00:18,120 --> 00:00:22,720
Here, the function records work and returns done.

9
00:00:22,720 --> 00:00:27,480
Before the caller gets done, using calls the cleanup method.

10
00:00:27,480 --> 00:00:30,840
The order is work, dispose, done.

11
00:00:31,020 --> 00:00:34,820
So where did the extra JavaScript come from?

12
00:00:35,000 --> 00:00:37,350
For this target, the compiler adds

13
00:00:37,350 --> 00:00:40,640
helper functions and a try finally structure.

14
00:00:40,640 --> 00:00:44,760
Finally runs on normal exit, return, or an error.

15
00:00:44,760 --> 00:00:48,160
The helpers track the resource and call cleanup.

16
00:00:48,340 --> 00:00:53,860
If your resource only has close, use try finally yourself.

17
00:00:53,860 --> 00:00:56,745
Using needs a compatible resource and

18
00:00:56,745 --> 00:00:59,300
runtime support for Symbol dot dispose.

19
00:00:59,480 --> 00:01:03,300
Cleanup releases a resource at a known point.

20
00:01:03,300 --> 00:01:06,500
Garbage collection manages unreachable memory.

21
00:01:06,500 --> 00:01:08,340
These are different jobs.

22
00:01:08,340 --> 00:01:11,280
Async cleanup needs a separate approach.

23
00:01:11,460 --> 00:01:14,400
The compiler cleans up after me.

24
00:01:14,400 --> 00:01:16,620
My apartment would like this feature.
