Skip to content
Browse files

Fix memory leaks in Hackbook

Summary:
1) img was alloc'ed and never released while uploading a photo
2) alertview was alloc'ed and never released
3) friendswithapp was alloc'ed twice and never released, updated the logic to use obj c syntax
4) UIGraphicsGetImageFromCurrentImageContext() returns an autoreleased imageView - retaining it is the incorrect solution. See http://stackoverflow.com/questions/1529667/memory-allocation-and-release-for-uiimage-in-iphone

Test Plan:
Run Hackbook in the profiler and verify no memory leaks when loading userpic from the graph api
Upload a photo, verify no longer leaks
View friends with app, verify no longer leaks
Pop the alertview and verify no longer leaks

Reviewers: jacl, caabernathy, mattwkelly, selekman

Reviewed By: jacl

Differential Revision: https://phabricator.fb.com/D430905

Task ID: 980129
  • Loading branch information...
1 parent 81c2954 commit 07626c3c641b532e70b423865d2694e0f1e4e2b8 Eric Osgood committed Mar 19, 2012
View
9 sample/Hackbook/Hackbook/APICallsViewController.m
@@ -559,6 +559,7 @@ - (void)enableFrictionlessAppRequests {
otherButtonTitles:nil,
nil];
[alertView show];
+ [alertView release];
}
/*
@@ -697,6 +698,8 @@ - (void)apiGraphUserPhotosPost {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, @"picture",
nil];
+ [img release];
+
[[delegate facebook] requestWithGraphPath:@"me/photos"
andParams:params
andHttpMethod:@"POST"
@@ -995,15 +998,17 @@ - (void)request:(FBRequest *)request didLoad:(id)result {
NSMutableArray *friendsWithApp = [[NSMutableArray alloc] initWithCapacity:1];
// Many results
if ([result isKindOfClass:[NSArray class]]) {
- friendsWithApp = [[NSMutableArray alloc] initWithArray:result copyItems:YES];
+ [friendsWithApp addObjectsFromArray:result];
} else if ([result isKindOfClass:[NSDecimalNumber class]]) {
- friendsWithApp = [[NSMutableArray alloc] initWithObjects:[result stringValue], nil];
+ [friendsWithApp addObject: [result stringValue]];
}
+
if ([friendsWithApp count] > 0) {
[self apiDialogRequestsSendToUsers:friendsWithApp];
} else {
[self showMessage:@"None of your friends are using the app."];
}
+
[friendsWithApp release];
break;
}
View
3 sample/Hackbook/Hackbook/APIResultsViewController.m
@@ -290,9 +290,6 @@ - (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)respons
* didReceiveResponse:(NSURLResponse *)response
*/
- (void)request:(FBRequest *)request didLoad:(id)result {
- if ([result isKindOfClass:[NSArray class]]) {
- result = [result objectAtIndex:0];
- }
[self showMessage:@"Checked in successfully"];
}
View
6 sample/Hackbook/Hackbook/RootViewController.m
@@ -429,10 +429,10 @@ - (void)request:(FBRequest *)request didLoad:(id)result {
UIGraphicsBeginImageContext(CGSizeMake(px, px));
UIRectClip(clipRect);
[image drawInRect:clipRect];
- UIImage *imgThumb = UIGraphicsGetImageFromCurrentImageContext();
- [imgThumb retain];
-
+ UIImage *imgThumb = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
[profilePhotoImageView setImage:imgThumb];
+
[self apiGraphUserPermissions];
} else {
// Processing permissions information

0 comments on commit 07626c3

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