From 859ad32e44fc500d8b4b1d1c14d3eb000ca39320 Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Fri, 10 Aug 2012 00:08:40 +0200 Subject: [PATCH] Advanced memory leak fixes --- Classes/LinphoneApp.xib | 36 +++++------------- Classes/LinphoneAppDelegate.h | 1 - Classes/LinphoneAppDelegate.m | 3 +- Classes/LinphoneManager.h | 7 +++- Classes/LinphoneManager.m | 37 ++++++++++++------- .../LinphoneUI/UICompositeViewController.m | 5 ++- Classes/LinphoneUI/UILongTouchButton.m | 6 +++ Classes/LinphoneUI/UIStateBar.m | 2 +- Classes/SettingsViewController.m | 6 +++ Classes/Utils/FastAddressBook.m | 1 + 10 files changed, 56 insertions(+), 48 deletions(-) diff --git a/Classes/LinphoneApp.xib b/Classes/LinphoneApp.xib index d2f9903f2..a6ba1dc38 100644 --- a/Classes/LinphoneApp.xib +++ b/Classes/LinphoneApp.xib @@ -2,19 +2,19 @@ 1296 - 11E53 - 2549 - 1138.47 - 569.00 + 11D50 + 2182 + 1138.32 + 568.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 1498 + 1181 - IBProxyObject + IBUIWindow IBUICustomObject IBUIViewController - IBUIWindow + IBProxyObject com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -83,14 +83,6 @@ 10 - - - window - - - - 12 - @@ -104,6 +96,7 @@ 2 + LinphoneWindow -1 @@ -154,17 +147,6 @@ LinphoneAppDelegate NSObject - - window - UIWindow - - - window - - window - UIWindow - - IBProjectSource ./Classes/LinphoneAppDelegate.h @@ -256,6 +238,6 @@ YES 3 - 1498 + 1181 diff --git a/Classes/LinphoneAppDelegate.h b/Classes/LinphoneAppDelegate.h index bc83e5280..2983bccb0 100644 --- a/Classes/LinphoneAppDelegate.h +++ b/Classes/LinphoneAppDelegate.h @@ -33,7 +33,6 @@ BOOL started; } -@property (nonatomic, retain) IBOutlet UIWindow *window; @property (assign) BOOL started; @end diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index d12c0cf26..1075712d8 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -43,7 +43,6 @@ int __aeabi_idiv(int a, int b) { @implementation LinphoneAppDelegate -@synthesize window; @synthesize started; @@ -58,7 +57,6 @@ int __aeabi_idiv(int a, int b) { } - (void)dealloc { - [window release]; [super dealloc]; } @@ -85,6 +83,7 @@ int __aeabi_idiv(int a, int b) { } - (void)applicationWillResignActive:(UIApplication *)application { + if(![LinphoneManager isLcReady]) return; LinphoneCore* lc = [LinphoneManager getLc]; LinphoneCall* call = linphone_core_get_current_call(lc); if (call == NULL) diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 7e3adc7ef..c212ea7d8 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -75,7 +75,10 @@ typedef struct _LinphoneCallAppData { @public CallContext currentCallContextBeforeGoingBackground; } -+ (LinphoneManager*) instance; ++ (LinphoneManager*)instance; +#ifdef DEBUG ++ (void)instanceRelease; +#endif + (LinphoneCore*) getLc; + (BOOL)isLcReady; + (BOOL)runningOnIpad; @@ -89,7 +92,7 @@ typedef struct _LinphoneCallAppData { - (BOOL)resignActive; - (void)becomeActive; -- (void)kickOffNetworkConnection; ++ (void)kickOffNetworkConnection; - (void)setupNetworkReachabilityCallback; - (void)refreshRegisters; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 98cc5bad0..b7bfded46 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -155,6 +155,14 @@ struct codec_name_pref_table codec_pref_table[]={ return theLinphoneManager; } +#ifdef DEBUG ++ (void)instanceRelease { + if(theLinphoneManager != nil) { + [theLinphoneManager release]; + theLinphoneManager = nil; + } +} +#endif #pragma mark - Lifecycle Functions @@ -376,18 +384,17 @@ static void linphone_iphone_text_received(LinphoneCore *lc, LinphoneChatRoom *ro #pragma mark - Network Functions -- (void)kickOffNetworkConnection { ++ (void)kickOffNetworkConnection { /*start a new thread to avoid blocking the main ui in case of peer host failure*/ - [NSThread detachNewThreadSelector:@selector(runNetworkConnection) toTarget:self withObject:nil]; -} - -- (void)runNetworkConnection { - CFWriteStreamRef writeStream; - CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"192.168.0.200"/*"linphone.org"*/, 15000, nil, &writeStream); - CFWriteStreamOpen (writeStream); - const char* buff="hello"; - CFWriteStreamWrite (writeStream,(const UInt8*)buff,strlen(buff)); - CFWriteStreamClose (writeStream); + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + CFWriteStreamRef writeStream; + CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"192.168.0.200"/*"linphone.org"*/, 15000, nil, &writeStream); + CFWriteStreamOpen (writeStream); + const char* buff="hello"; + CFWriteStreamWrite (writeStream,(const UInt8*)buff,strlen(buff)); + CFWriteStreamClose (writeStream); + CFRelease(writeStream); + }); } static void showNetworkFlags(SCNetworkReachabilityFlags flags){ @@ -424,7 +431,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach if ((flags == 0) || (flags & networkDownFlags)) { linphone_core_set_network_reachable([LinphoneManager getLc],false); lLinphoneMgr.connectivity = none; - [[LinphoneManager instance] kickOffNetworkConnection]; + [LinphoneManager kickOffNetworkConnection]; } else { Connectivity newConnectivity; BOOL isWifiOnly = lp_config_get_int(linphone_core_get_config([LinphoneManager getLc]),"app","wifi_only_preference",FALSE); @@ -645,6 +652,10 @@ static LinphoneCoreVTable linphonec_vtable = { [mIterateTimer invalidate]; AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setDelegate:nil]; + if (settingsStore != nil) { + [settingsStore release]; + settingsStore = nil; + } if (theLinphoneCore != nil) { //just in case application terminate before linphone core initialization [LinphoneLogger logc:LinphoneLoggerLog format:"Destroy linphonecore"]; linphone_core_destroy(theLinphoneCore); @@ -688,7 +699,7 @@ static LinphoneCoreVTable linphonec_vtable = { return; } //kick up network cnx, just in case - [self kickOffNetworkConnection]; + [LinphoneManager kickOffNetworkConnection]; [self refreshRegisters]; linphone_core_iterate(theLinphoneCore); } diff --git a/Classes/LinphoneUI/UICompositeViewController.m b/Classes/LinphoneUI/UICompositeViewController.m index 2a28ad1a8..9ab23d6b3 100644 --- a/Classes/LinphoneUI/UICompositeViewController.m +++ b/Classes/LinphoneUI/UICompositeViewController.m @@ -126,7 +126,8 @@ [contentView release]; [stateBarView release]; [tabBarView release]; - [viewControllerCache removeAllObjects]; + [viewControllerCache release]; + [viewTransition release]; [currentViewDescription release]; [super dealloc]; @@ -251,7 +252,7 @@ if(name != nil) { controller = [viewControllerCache objectForKey:name]; if(controller == nil) { - controller = [[NSClassFromString(name) alloc] init]; + controller = [[[NSClassFromString(name) alloc] init] autorelease]; [viewControllerCache setValue:controller forKey:name]; [controller view]; // Load the view } diff --git a/Classes/LinphoneUI/UILongTouchButton.m b/Classes/LinphoneUI/UILongTouchButton.m index 012b2ef0e..c4f1b0a21 100644 --- a/Classes/LinphoneUI/UILongTouchButton.m +++ b/Classes/LinphoneUI/UILongTouchButton.m @@ -54,6 +54,12 @@ return self; } +- (void)dealloc { + [self removeTarget:self action:@selector(___touchDown:) forControlEvents:UIControlEventTouchDown]; + [self removeTarget:self action:@selector(___touchUp:) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside]; + [super dealloc]; +} + - (void)___touchDown:(id) sender { [self performSelector:@selector(doLongTouch) withObject:nil afterDelay:0.5]; } diff --git a/Classes/LinphoneUI/UIStateBar.m b/Classes/LinphoneUI/UIStateBar.m index 45914a3b9..af07b4f2e 100644 --- a/Classes/LinphoneUI/UIStateBar.m +++ b/Classes/LinphoneUI/UIStateBar.m @@ -161,7 +161,7 @@ NSTimer *callSecurityTimer; break; case LinphoneRegistrationNone: registrationStateImage.hidden = NO; - image =[UIImage imageNamed:@"led_disconnected.png"]; + image = [UIImage imageNamed:@"led_disconnected.png"]; break; case LinphoneRegistrationProgress: registrationStateImage.hidden = NO; diff --git a/Classes/SettingsViewController.m b/Classes/SettingsViewController.m index b834b7831..e5db3b200 100644 --- a/Classes/SettingsViewController.m +++ b/Classes/SettingsViewController.m @@ -348,6 +348,8 @@ - (void)dealloc { // Remove all observer [[NSNotificationCenter defaultCenter] removeObserver:self]; + [settingsController release]; + [navigationController release]; [super dealloc]; } @@ -499,6 +501,10 @@ static UICompositeViewDescription *compositeDescription = nil; NSString *key = [specifier.specifierDict objectForKey:kIASKKey]; #ifdef DEBUG if([key isEqual:@"release_button"]) { + [[UIApplication sharedApplication].keyWindow.rootViewController release]; + [[UIApplication sharedApplication].keyWindow setRootViewController:nil]; + [[LinphoneManager instance] destroyLibLinphone]; + [LinphoneManager instanceRelease]; } #endif } diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index 04ff318d5..7065ebd2d 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -172,6 +172,7 @@ void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef info, void - (void)dealloc { ABAddressBookUnregisterExternalChangeCallback(addressBook, sync_address_book, self); CFRelease(addressBook); + [addressBookMap release]; [super dealloc]; }