Commit 0062608
committed
OSX/MACOS: Make [CocoaView get] honour the +0 "get" convention
+[CocoaView get] is a cached-singleton accessor. By Cocoa
convention a method whose name does not start with new / alloc /
copy / mutableCopy returns a +0 (unretained) reference; the
singleton is kept alive by the storage it is cached in.
The existing implementation violated that convention on the
first-time path: it did [CocoaView new] (+1) and handed the
pointer to nsview_set_ptr, which was a raw `g_instance = p;` -
no retain. The caller then received a +1 return on the first
call but +0 on every call thereafter. Under ARC the strong
static would retain on store so it was self-consistent, but
under MRR the first-ever caller had an unbalanced +1 the code
never handled - a small process-lifetime leak. A prior commit
(e9279a8) leaned into the +0 assumption by adding RARCH_RETAIN
wrappers in ui_cocoa.m, which silently turned that +1 into a
+2 leak whenever -setViewType: was called for a singleton-
backed view type on its first use.
Two changes, both behind the existing RARCH_* macros so ARC
builds see no-ops:
- +[CocoaView get]: autorelease the freshly-allocated instance
before storing. The returned pointer is now +0 on every path,
matching the get naming convention.
- nsview_set_ptr: take a proper strong reference for the
g_instance slot (retain new, release old). g_instance is
now the single owner of the singleton's +1, matching how the
rest of the codebase already treats it (never nil-ed, never
explicitly released - so the retain lives for the process
lifetime, which is the intent).
Adds #include <defines/cocoa_defines.h> to cocoa_common.m for
RARCH_RETAIN / RARCH_RELEASE / RARCH_AUTORELEASE. The include
path is already on every Apple build config (already used by
ui_cocoa.m, dispserv_apple.m, coreaudio.c).
No behavioural change under ARC. On MRR, plugs the first-call
+1 leak and cancels the +2 over-retain that e9279a8's RARCH_RETAIN
wrappers would otherwise produce.1 parent e0b7b9b commit 0062608
1 file changed
Lines changed: 31 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
206 | 207 | | |
207 | 208 | | |
208 | 209 | | |
209 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
210 | 221 | | |
211 | 222 | | |
212 | 223 | | |
| |||
936 | 947 | | |
937 | 948 | | |
938 | 949 | | |
939 | | - | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
940 | 969 | | |
941 | 970 | | |
942 | 971 | | |
| |||
0 commit comments