1
00:00:00,000 --> 00:00:02,380
I close this panel, open it

2
00:00:02,380 --> 00:00:05,000
again, and resize the window.

3
00:00:05,000 --> 00:00:07,480
Why does the same work run twice?

4
00:00:07,660 --> 00:00:11,000
Each opening adds a new window listener.

5
00:00:11,000 --> 00:00:15,000
Removing the panel does not remove that listener.

6
00:00:15,000 --> 00:00:17,000
Closing twice can leave two callbacks

7
00:00:17,000 --> 00:00:19,060
waiting for the next resize.

8
00:00:19,240 --> 00:00:22,000
The window keeps the callback.

9
00:00:22,000 --> 00:00:25,000
The callback keeps the panel it uses.

10
00:00:25,000 --> 00:00:28,290
Garbage collection frees unreachable objects.

11
00:00:28,290 --> 00:00:30,530
This panel is still reachable, even

12
00:00:30,530 --> 00:00:32,120
though you cannot see it.

13
00:00:32,300 --> 00:00:33,370
So I need to remove the

14
00:00:33,370 --> 00:00:36,000
listener when I close the panel.

15
00:00:36,000 --> 00:00:37,700
How?

16
00:00:37,880 --> 00:00:41,180
Create an AbortController for each opening and

17
00:00:41,180 --> 00:00:44,000
pass its signal when adding the listener.

18
00:00:44,000 --> 00:00:47,000
On close, abort removes that listener.

19
00:00:47,000 --> 00:00:48,440
Then remove the panel.

20
00:00:48,620 --> 00:00:52,000
You can also remove the listener directly.

21
00:00:52,000 --> 00:00:53,500
Keep the same function reference

22
00:00:53,500 --> 00:00:55,000
and the same capture setting.

23
00:00:55,000 --> 00:00:58,900
A new arrow function will not match the old listener.

24
00:00:59,080 --> 00:01:02,000
Repeat the same steps after cleanup.

25
00:01:02,000 --> 00:01:05,000
Now only the open panel reacts.

26
00:01:05,000 --> 00:01:09,450
This removes one reference path; other references may

27
00:01:09,450 --> 00:01:11,160
still keep the old panel in memory.

28
00:01:11,340 --> 00:01:16,000
I deleted the panel, but kept paying it to work.

29
00:01:16,000 --> 00:01:18,940
I accidentally built middle management.
