Commit 13cfac6
authored
[ios] fix memory leak in Editor (#16348)
Context: #16346
This addresses the memory leak discovered by:
src/Core/src/Platform/iOS/MauiTextView.cs(37,30): error MA0001: Event 'TextSetOrChanged' could cause memory leaks in an NSObject subclass. Remove the event or add the [UnconditionalSuppressMessage("Memory", "MA0001")] attribute with a justification as to why the event will not leak.
src/Core/src/Platform/iOS/MauiTextView.cs(12,20): error MA0002: Member '_placeholderLabel' could cause memory leaks in an NSObject subclass. Remove the member, store the value as a WeakReference, or add the [UnconditionalSuppressMessage("Memory", "MA0002")] attribute with a justification as to why the member will not leak.
I could reproduce a leak in a test such as:
await InvokeOnMainThreadAsync(() =>
{
var layout = new Grid();
var editor = new Editor();
layout.Add(editor);
var handler = CreateHandler<LayoutHandler>(layout);
viewReference = new WeakReference(editor);
handlerReference = new WeakReference(editor.Handler);
platformViewReference = new WeakReference(editor.Handler.PlatformView);
});
await AssertionExtensions.WaitForGC(viewReference, handlerReference, platformViewReference);
Assert.False(viewReference.IsAlive, "Editor should not be alive!");
Assert.False(handlerReference.IsAlive, "Handler should not be alive!");
Assert.False(platformViewReference.IsAlive, "PlatformView should not be alive!");
I will create a similar PR for `Entry` as well.1 parent 0fb5704 commit 13cfac6
File tree
3 files changed
+113
-41
lines changed- src
- Controls/tests/DeviceTests/Elements/Editor
- Core/src
- Handlers/Editor
- Platform/iOS
3 files changed
+113
-41
lines changedLines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
13 | 50 | | |
14 | 51 | | |
15 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 43 | + | |
47 | 44 | | |
48 | 45 | | |
49 | 46 | | |
50 | 47 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 48 | + | |
55 | 49 | | |
56 | 50 | | |
57 | 51 | | |
58 | 52 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 53 | + | |
68 | 54 | | |
69 | 55 | | |
70 | 56 | | |
| |||
152 | 138 | | |
153 | 139 | | |
154 | 140 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 141 | + | |
159 | 142 | | |
160 | | - | |
161 | | - | |
162 | | - | |
| 143 | + | |
| 144 | + | |
163 | 145 | | |
164 | | - | |
165 | | - | |
166 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
167 | 149 | | |
168 | | - | |
| 150 | + | |
169 | 151 | | |
170 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
171 | 156 | | |
172 | | - | |
173 | 157 | | |
174 | | - | |
175 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
176 | 161 | | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
181 | 193 | | |
182 | | - | |
183 | | - | |
| 194 | + | |
| 195 | + | |
184 | 196 | | |
185 | | - | |
186 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
187 | 219 | | |
188 | 220 | | |
189 | 221 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| |||
0 commit comments