Skip to content
Browse files

Implement handler and setHandler: dynamically instead of synthesized …

…to ensure that the runtime is not inserting autorelease calls.
  • Loading branch information...
1 parent 584e29a commit 5b32a5616ce27b71c9edcfb6ca85f38674d5fc2b @adamjernst committed Dec 23, 2011
Showing with 22 additions and 3 deletions.
  1. +22 −3 AEURLConnection/AEURLConnection.m
View
25 AEURLConnection/AEURLConnection.m
@@ -9,10 +9,12 @@
#import "AEURLConnection.h"
-@interface AEURLConnectionRequest : NSObject
+@interface AEURLConnectionRequest : NSObject {
+ id _handler;
+}
- (id)initWithRequest:(NSURLRequest *)request
queue:(NSOperationQueue *)queue
- processor:(AEURLResponseProcessor)processor
+ processor:(AEURLResponseProcessor)processor
completionHandler:handler;
@property (nonatomic, retain, readonly) NSURLRequest *request;
@property (nonatomic, retain, readonly) NSOperationQueue *queue;
@@ -282,7 +284,7 @@ @implementation AEURLConnectionRequest
@synthesize request=_request;
@synthesize queue=_queue;
@synthesize processor=_processor;
-@synthesize handler=_handler;
+@dynamic handler;
@synthesize connection=_connection;
@synthesize response=_response;
@@ -315,5 +317,22 @@ - (void)dealloc {
[super dealloc];
}
+// The |handler| getter and setter are dynamic instead of synthesized to
+// make sure that the runtime doesn't pull any tricks with autorelease
+// (which would negate our guarantee that handler is released on the target
+// queue). Thanks to Mike Ash for suggesting I avoid synthesized getters for
+// this reason.
+
+- (id)handler {
+ return _handler;
+}
+
+- (void)setHandler:(id)newHandler {
+ if (newHandler != _handler) {
+ [_handler release];
+ _handler = [newHandler retain];
+ }
+}
+
@end

0 comments on commit 5b32a56

Please sign in to comment.
Something went wrong with that request. Please try again.