Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

iOS SDK: fix memory issue in SDK and theRunAround demo App

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...
commit 87c902c998f460366783610815a7daaf0869f098 1 parent fce25d8
Yujuan Bao authored
View
11 sample/theRunAround/Classes/Session.m
@@ -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];
@@ -94,5 +94,12 @@ - (id) restore {
return nil;
}
+- (void)dealloc {
+ [_facebook.accessToken release];
+ [_facebook.expirationDate release];
+ [_facebook release];
+ [_uid release];
+ [super dealloc];
+}
@end
View
1  sample/theRunAround/Classes/UserInfo.m
@@ -44,6 +44,7 @@ - (void)dealloc {
[_uid release];
[_friendsList release];
[_friendsInfo release];
+ [_userInfoDelegate release];
[super dealloc];
}
View
4 sample/theRunAround/Classes/UserRequestResult.m
@@ -25,6 +25,10 @@ - (id) initializeWithDelegate:(id<UserRequestDelegate>)delegate {
return self;
}
+- (void)dealloc {
+ [_userRequestDelegate release];
+ [super dealloc];
+}
/**
* FBRequestDelegate
View
2  src/Facebook.h
@@ -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;
View
12 src/Facebook.m
@@ -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];
@@ -425,16 +425,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
*/
Please sign in to comment.
Something went wrong with that request. Please try again.