Commit 2268a81
authored
NSWindow.ReleasedWhenClosed is a rather annoying API, because it interferes with
reference counting. In effect it behaves kind of like autoreleasing does, except
that the object (window) is released at a different time (when the window is closed,
as opposed to when the autorelease pool drains).
We've tried to fix this in the past in several ways:
* Forcefully disable ReleasedWhenClosed in all the constructors, and if it's set
in the Close method, then add an extra Retain call to offset the imminent extra
release. The unfortunate side-effect is that we also call Dispose, which might
be too early (see #8606).
* Rewrite the code to correctly override the native 'close' method, so we get the
supposedly correct semantics (our special Close code is called) when the window
is closed by Objective-C (for instance when the user hits the red X to close the
window). This doesn't really solve the previous problem (we're calling Dispose
too early), and it doesn't work for non-subclassed NSWindows (see #8717).
So I'm trying another approach: track the value of ReleasedWhenClosed, and call Retain/Release
when the value switches between true/false. This way we don't need any special logic
in the Close method.
I've also:
* Marked the ReleasedWhenClosed property as obsolete, and added a DangerousReleasedWhenClosed
property, to match how we bind the other reference counting methods (retain ->
DangerousRetain, release -> DangerousRelease, etc.).
* Added a ReleaseWhenClosed(bool) method, to be called instead of the ReleasedWhenClosed
property, and this method will call DangerousRetain/DangerousRelease as described
above when the ReleasedWhenClosed property changes value.
This new tracking behavior is opt-in for now, but will become opt-out in .NET 9,
and hopefully we'll be able to make it the only behavior at some point (in .NET 10
maybe?).
Fixes #8606.
Fixes #8607.
Ref: #8717.
1 parent efad190 commit 2268a81
2 files changed
Lines changed: 73 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
35 | 40 | | |
36 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
37 | 62 | | |
38 | 63 | | |
39 | 64 | | |
| |||
47 | 72 | | |
48 | 73 | | |
49 | 74 | | |
50 | | - | |
51 | | - | |
| 75 | + | |
52 | 76 | | |
53 | 77 | | |
54 | 78 | | |
55 | 79 | | |
56 | 80 | | |
57 | 81 | | |
58 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
59 | 111 | | |
60 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
61 | 118 | | |
62 | 119 | | |
63 | 120 | | |
64 | 121 | | |
65 | 122 | | |
66 | 123 | | |
67 | 124 | | |
68 | | - | |
| 125 | + | |
69 | 126 | | |
70 | 127 | | |
71 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20637 | 20637 | | |
20638 | 20638 | | |
20639 | 20639 | | |
20640 | | - | |
| 20640 | + | |
20641 | 20641 | | |
20642 | 20642 | | |
20643 | 20643 | | |
20644 | 20644 | | |
20645 | | - | |
| 20645 | + | |
20646 | 20646 | | |
20647 | 20647 | | |
20648 | 20648 | | |
20649 | | - | |
| 20649 | + | |
20650 | 20650 | | |
20651 | 20651 | | |
20652 | 20652 | | |
| |||
20801 | 20801 | | |
20802 | 20802 | | |
20803 | 20803 | | |
| 20804 | + | |
| 20805 | + | |
20804 | 20806 | | |
20805 | 20807 | | |
| 20808 | + | |
| 20809 | + | |
| 20810 | + | |
| 20811 | + | |
| 20812 | + | |
| 20813 | + | |
| 20814 | + | |
| 20815 | + | |
20806 | 20816 | | |
20807 | 20817 | | |
20808 | 20818 | | |
| |||
0 commit comments