Skip to content

Commit

Permalink
iOS SDK: fix memory issue in SDK and theRunAround demo App
Browse files Browse the repository at this point in the history
summary:
Fix some memory leak and dealloc issues

The Facebook.m -logout: method calls this:

[self requestWithMethodName:@"auth.expireSession"
andParams:params andHttpMethod:@"GET"
andDelegate:self];

By setting the Facebook object as the delegate, it gets retained by the FBRequest object, but in turn the -openUrl:params:httpMethod:delegate: method retains the request itself in the _request instance variable. This creates a retain cycle, and neither object will be freed.

-in Session.m, there is a missing retain on the uid in -restore -in Session.m there is no dealloc method — one should be added to free facebook and uid -in UserInfo.m, the dealloc needs to release the userInfoDelegate that was retained -in UserRequestResult.m there is no dealloc — one should be added to free userRequestDelegate

test plan:
theRunAroundDemoApp, open the app login and turn off the app without log out. bring the app up again. make sure we are logged in and all the session info bring back correctly.

Run the unittest
  • Loading branch information
Yujuan Bao committed Sep 23, 2010
1 parent fce25d8 commit 87c902c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
11 changes: 9 additions & 2 deletions sample/theRunAround/Classes/Session.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ - (id) restore {
if (uid) {
NSDate* expirationDate = [defaults objectForKey:@"FBSessionExpires"];
if (!expirationDate || [expirationDate timeIntervalSinceNow] > 0) {
_uid = uid;
_facebook = [[[[Facebook alloc] init] retain] autorelease];
_uid = [uid copy];
_facebook = [[Facebook alloc] init];
_facebook.accessToken = [[defaults stringForKey:@"FBAccessToken"] copy];
_facebook.expirationDate = [expirationDate retain];

Expand All @@ -94,5 +94,12 @@ - (id) restore {
return nil;
}

- (void)dealloc {
[_facebook.accessToken release];
[_facebook.expirationDate release];
[_facebook release];
[_uid release];
[super dealloc];
}

@end
1 change: 1 addition & 0 deletions sample/theRunAround/Classes/UserInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ - (void)dealloc {
[_uid release];
[_friendsList release];
[_friendsInfo release];
[_userInfoDelegate release];
[super dealloc];
}

Expand Down
4 changes: 4 additions & 0 deletions sample/theRunAround/Classes/UserRequestResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ - (id) initializeWithDelegate:(id<UserRequestDelegate>)delegate {
return self;
}

- (void)dealloc {
[_userRequestDelegate release];
[super dealloc];
}

/**
* FBRequestDelegate
Expand Down
2 changes: 1 addition & 1 deletion src/Facebook.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* and Graph APIs, and start user interface interactions (such as
* pop-ups promoting for credentials, permissions, stream posts, etc.)
*/
@interface Facebook : NSObject<FBLoginDialogDelegate, FBRequestDelegate>{
@interface Facebook : NSObject<FBLoginDialogDelegate>{
NSString* _accessToken;
NSDate* _expirationDate;
id<FBSessionDelegate> _sessionDelegate;
Expand Down
12 changes: 1 addition & 11 deletions src/Facebook.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ - (void)logout:(id<FBSessionDelegate>)delegate {
NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
[self requestWithMethodName:@"auth.expireSession"
andParams:params andHttpMethod:@"GET"
andDelegate:self];
andDelegate:nil];

[params release];
[_accessToken release];
Expand Down Expand Up @@ -424,16 +424,6 @@ - (void) fbDialogNotLogin:(BOOL)cancelled {
}


///////////////////////////////////////////////////////////////////////////////////////////////////
//FBRequestDelegate

/**
* Handle the auth.ExpireSession api call failure
*/
- (void)request:(FBRequest*)request didFailWithError:(NSError*)error{
NSLog(@"Failed to expire the session");
}

///////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Override NSObject : free the space
Expand Down

0 comments on commit 87c902c

Please sign in to comment.