Differences From Artifact [a7b0a81fd8]:
- File src/OFNotificationCenter.m — part of check-in [c40a295629] at 2022-09-12 14:34:38 on branch trunk — Either restrict subclassing or reserve ivars (user: js, size: 8193) [annotate] [blame] [check-ins using] [more...]
To Artifact [bec84a1cd3]:
- File
src/OFNotificationCenter.m
— part of check-in
[5b5c12fa0b]
at
2023-01-13 13:31:07
on branch trunk
— OFNotificationCenter: Don't retain observer
This avoids retain cycles.
A future improvement could be to use a weak reference instead, without
relying on ARC by calling into the runtime functions directly. (user: js, size: 8291) [annotate] [blame] [check-ins using] [more...]
1 | /* | | | 1 2 3 4 5 6 7 8 9 | /* * Copyright (c) 2008-2023 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * |
︙ | ︙ | |||
65 66 67 68 69 70 71 | { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); _name = [name copy]; | | | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); _name = [name copy]; _observer = observer; _selector = selector; _object = [object retain]; _selectorHash = [[OFString stringWithUTF8String: sel_getName(_selector)] hash]; objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
104 105 106 107 108 109 110 | return self; } #endif - (void)dealloc { [_name release]; | < | 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | return self; } #endif - (void)dealloc { [_name release]; [_object release]; #ifdef OF_HAVE_BLOCKS [_block release]; #endif [super dealloc]; } |
︙ | ︙ | |||
243 244 245 246 247 248 249 | object: object] autorelease]]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS | < | | | | > > > > > > > | | 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | object: object] autorelease]]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (id)addObserverForName: (OFNotificationName)name object: (id)object usingBlock: (OFNotificationCenterBlock)block { void *pool = objc_autoreleasePoolPush(); OFNotificationCenterHandle *handle = [[[OFNotificationCenterHandle alloc] initWithName: name object: object block: block] autorelease]; [self of_addObserver: handle]; [handle retain]; objc_autoreleasePoolPop(pool); return [handle autorelease]; } #endif - (void)removeObserver: (id)handle_ { OFNotificationCenterHandle *handle; void *pool; if (![handle_ isKindOfClass: [OFNotificationCenterHandle class]]) @throw [OFInvalidArgumentException exception]; handle = handle_; pool = objc_autoreleasePoolPush(); /* {} required to avoid -Wmisleading-indentation false positive. */ if (![handle isKindOfClass: [OFNotificationCenterHandle class]]) { @throw [OFInvalidArgumentException exception]; } #ifdef OF_HAVE_THREADS |
︙ | ︙ |