Permalink
Browse files

plugs leaks

  • Loading branch information...
1 parent 13d4d5b commit c22a8f84d9d28bd5f24184f2657241aee1a8356e Evadne Wu committed Feb 2, 2012
View
104 IRRemoteResourcesManager.m
@@ -307,56 +307,60 @@ - (void) retrieveResourceAtURL:(NSURL *)anURL usingPriority:(NSOperationQueuePri
- (void) enqueueOperationsIfNeeded {
- NSComparator operationQueuePriorityComparator = (NSComparator) ^ (NSOperation *lhs, NSOperation *rhs) {
- return (lhs.queuePriority < rhs.queuePriority) ? NSOrderedDescending :
- (lhs.queuePriority == rhs.queuePriority) ? NSOrderedSame :
- (lhs.queuePriority > rhs.queuePriority) ? NSOrderedAscending : NSOrderedSame;
- };
-
- NSArray * (^sorted)(NSArray *) = ^ (NSArray *anArray) {
- return [anArray sortedArrayUsingComparator:operationQueuePriorityComparator];
- };
-
- NSArray * (^filtered)(NSArray *, BOOL(^)(id, NSDictionary *)) = ^ (NSArray *filteredArray, BOOL(^predicate)(id evaluatedObject, NSDictionary *bindings)) {
- return [filteredArray filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:predicate]];
- };
-
- NSArray *usableCurrentOperations = filtered(self.queue.operations, ^ (NSOperation *anOperation, NSDictionary *bindings){
- return (BOOL)![anOperation isCancelled];
- });
-
- NSArray *usableEnqueuedOperations = filtered(self.enqueuedOperations, ^ (NSOperation *anOperation, NSDictionary *bindings){
- return (BOOL)![anOperation isCancelled];
- });
-
- for (NSOperation *anOperation in usableCurrentOperations)
- NSParameterAssert(![anOperation isCancelled]);
-
- NSArray *sortedCurrentOperations = sorted(self.queue.operations);
- NSArray *sortedEnqueuedOperations = sorted(usableEnqueuedOperations);
- NSArray *sortedAllOperations = sorted([sortedCurrentOperations arrayByAddingObjectsFromArray:sortedEnqueuedOperations]);
-
- NSArray *legitimateOperations = [sortedAllOperations objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:(NSRange){
- 0, MIN(self.queue.maxConcurrentOperationCount, [sortedAllOperations count])
- }]];
-
- NSArray *insertedOperations = filtered(legitimateOperations, ^ (id evaluatedObject, NSDictionary *bindings) {
- return (BOOL)![sortedCurrentOperations containsObject:evaluatedObject];
- });
-
- NSArray *postponedOperations = filtered(sortedCurrentOperations, ^ (id evaluatedObject, NSDictionary *bindings) {
- return (BOOL)![legitimateOperations containsObject:evaluatedObject];
- });
-
- for (NSOperation *anOperation in insertedOperations)
- if (![self.queue.operations containsObject:anOperation])
- [self.queue addOperation:anOperation];
-
- [self.enqueuedOperations removeObjectsInArray:insertedOperations];
-
- [postponedOperations enumerateObjectsUsingBlock: ^ (IRRemoteResourceDownloadOperation *anOperation, NSUInteger idx, BOOL *stop) {
- [self.enqueuedOperations addObject:[anOperation continuationOperationCancellingCurrentOperation:YES]];
- }];
+ @autoreleasepool {
+
+ NSComparator operationQueuePriorityComparator = (NSComparator) ^ (NSOperation *lhs, NSOperation *rhs) {
+ return (lhs.queuePriority < rhs.queuePriority) ? NSOrderedDescending :
+ (lhs.queuePriority == rhs.queuePriority) ? NSOrderedSame :
+ (lhs.queuePriority > rhs.queuePriority) ? NSOrderedAscending : NSOrderedSame;
+ };
+
+ NSArray * (^sorted)(NSArray *) = ^ (NSArray *anArray) {
+ return [anArray sortedArrayUsingComparator:operationQueuePriorityComparator];
+ };
+
+ NSArray * (^filtered)(NSArray *, BOOL(^)(id, NSDictionary *)) = ^ (NSArray *filteredArray, BOOL(^predicate)(id evaluatedObject, NSDictionary *bindings)) {
+ return [filteredArray filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:predicate]];
+ };
+
+ NSArray *usableCurrentOperations = filtered(self.queue.operations, ^ (NSOperation *anOperation, NSDictionary *bindings){
+ return (BOOL)![anOperation isCancelled];
+ });
+
+ NSArray *usableEnqueuedOperations = filtered(self.enqueuedOperations, ^ (NSOperation *anOperation, NSDictionary *bindings){
+ return (BOOL)![anOperation isCancelled];
+ });
+
+ for (NSOperation *anOperation in usableCurrentOperations)
+ NSParameterAssert(![anOperation isCancelled]);
+
+ NSArray *sortedCurrentOperations = sorted(self.queue.operations);
+ NSArray *sortedEnqueuedOperations = sorted(usableEnqueuedOperations);
+ NSArray *sortedAllOperations = sorted([sortedCurrentOperations arrayByAddingObjectsFromArray:sortedEnqueuedOperations]);
+
+ NSArray *legitimateOperations = [sortedAllOperations objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:(NSRange){
+ 0, MIN(self.queue.maxConcurrentOperationCount, [sortedAllOperations count])
+ }]];
+
+ NSArray *insertedOperations = filtered(legitimateOperations, ^ (id evaluatedObject, NSDictionary *bindings) {
+ return (BOOL)![sortedCurrentOperations containsObject:evaluatedObject];
+ });
+
+ NSArray *postponedOperations = filtered(sortedCurrentOperations, ^ (id evaluatedObject, NSDictionary *bindings) {
+ return (BOOL)![legitimateOperations containsObject:evaluatedObject];
+ });
+
+ for (NSOperation *anOperation in insertedOperations)
+ if (![self.queue.operations containsObject:anOperation])
+ [self.queue addOperation:anOperation];
+
+ [self.enqueuedOperations removeObjectsInArray:insertedOperations];
+
+ [postponedOperations enumerateObjectsUsingBlock: ^ (IRRemoteResourceDownloadOperation *anOperation, NSUInteger idx, BOOL *stop) {
+ [self.enqueuedOperations addObject:[anOperation continuationOperationCancellingCurrentOperation:YES]];
+ }];
+
+ }
}
View
2 IRWebAPIEngine+FormMultipart.m
@@ -27,7 +27,7 @@ + (IRWebAPIRequestContextTransformer) defaultFormMultipartTransformer {
NSError *error;
- NSURL *fileHandleURL = [[self class] newTemporaryFileURL];
+ NSURL *fileHandleURL = [[[self class] newTemporaryFileURL] autorelease];
if (![[NSFileManager defaultManager] createFileAtPath:[fileHandleURL path] contents:[NSData data] attributes:nil]) {
View
6 IRWebAPIGoogleReaderAuthenticator.m
@@ -35,15 +35,13 @@ - (void) createTransformerBlocks {
return (NSDictionary *)transformedContext;
- } copy] retain];
+ } copy] autorelease];
self.globalResponsePreTransformerBlock = [[^ (NSDictionary *inParsedResponse, NSDictionary *inResponseContext) {
- // FIXME: Probably add code to handle possible authentication failure and trigger synchronous, blocking reauthentication?
-
return inParsedResponse;
- } copy] retain];
+ } copy] autorelease];
}
View
2 IRWebAPIGoogleReaderInterface.m
@@ -29,7 +29,7 @@ - (id) init {
IRWebAPIContext *googleReaderContext = [[[IRWebAPIContext alloc] initWithBaseURL:[NSURL URLWithString:@"https://www.google.com"]] autorelease];
IRWebAPIEngine *googleReaderEngine = [[[IRWebAPIEngine alloc] initWithContext:googleReaderContext] autorelease];
- IRWebAPIAuthenticator *googleReaderAuthenticator = [[IRWebAPIGoogleReaderAuthenticator alloc] initWithEngine:googleReaderEngine];
+ IRWebAPIAuthenticator *googleReaderAuthenticator = [[[IRWebAPIGoogleReaderAuthenticator alloc] initWithEngine:googleReaderEngine] autorelease];
googleReaderEngine.parser = IRWebAPIResponseDefaultJSONParserMake();
View
2 IRWebAPITwitPicInterface.m
@@ -58,7 +58,7 @@ - (void) uploadImage:(UIImage *)inImage onProgress:(void(^)(float inProgressRati
}
- NSURL *cachingFileURL = [[self.engine class] newTemporaryFileURL];
+ NSURL *cachingFileURL = [[[self.engine class] newTemporaryFileURL] autorelease];
[imageDataOrNil writeToURL:cachingFileURL atomically:YES];
View
2 IRWebAPITwitterInterface+Geo.m
@@ -99,7 +99,7 @@ - (void) reverseGeocodeWithLocation:(CLLocation *)inLocation userinfo:(NSDiction
}
- NSArray *places = [inResponseOrNil valueForKey:@"result.places"];
+ // NSArray *places = [inResponseOrNil valueForKey:@"result.places"];
NSLog(@"geo/reverse_geocode response: %@", inResponseOrNil);

0 comments on commit c22a8f8

Please sign in to comment.