fix a couple of 'potential leaks'
authorkoda
Sat, 01 Oct 2011 03:06:51 +0200
changeset 6076 e1b4771f6472
parent 6075 0173cd44c3bc
child 6077 d8fa5a85d24f
fix a couple of 'potential leaks'
project_files/HedgewarsMobile/Classes/InGameMenuViewController.h
project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
project_files/HedgewarsMobile/Classes/SettingsBaseViewController.h
project_files/HedgewarsMobile/Classes/SettingsBaseViewController.m
project_files/HedgewarsMobile/Classes/SettingsContainerViewController.h
project_files/HedgewarsMobile/Classes/SettingsContainerViewController.m
--- a/project_files/HedgewarsMobile/Classes/InGameMenuViewController.h	Sat Oct 01 02:49:40 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/InGameMenuViewController.h	Sat Oct 01 03:06:51 2011 +0200
@@ -31,6 +31,6 @@
 
 -(void) present;
 -(void) dismiss;
--(void) saveCurrentScreenToPhotoAlbum:(UIAlertView *)alert;
+//-(void) saveCurrentScreenToPhotoAlbum:(UIAlertView *)alert;
 
 @end
--- a/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m	Sat Oct 01 02:49:40 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m	Sat Oct 01 03:06:51 2011 +0200
@@ -90,6 +90,7 @@
 
     SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow());
 
+    /*
     if (shouldTakeScreenshot) {
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please wait"
                                                         message:nil
@@ -107,6 +108,7 @@
         // all these hacks because of the PAUSE caption on top of everything...
         [self performSelector:@selector(saveCurrentScreenToPhotoAlbum:) withObject:alert afterDelay:0.3];
     }
+    */
     shouldTakeScreenshot = NO;
 }
 
@@ -192,6 +194,7 @@
 }
 
 //TODO: check this is still needed since we switched to SDL_GL_CreateContext()
+/*
 #pragma mark -
 #pragma mark save screenshot
 //by http://www.bit-101.com/blog/?p=1861
@@ -247,6 +250,6 @@
     // add callback for cleaning memory and removing alert
     UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (void *)alert);
 }
-
+*/
 
 @end
--- a/project_files/HedgewarsMobile/Classes/SettingsBaseViewController.h	Sat Oct 01 02:49:40 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SettingsBaseViewController.h	Sat Oct 01 03:06:51 2011 +0200
@@ -32,6 +32,7 @@
     UIViewController *targetController;
     NSArray *controllerNames;
     NSIndexPath *lastIndexPath;
+    UITabBarController *tabController;
     GeneralSettingsViewController *generalSettingsViewController;
     TeamSettingsViewController *teamSettingsViewController;
     WeaponSettingsViewController *weaponSettingsViewController;
@@ -42,6 +43,7 @@
 @property (nonatomic, retain) UIViewController *targetController;
 @property (nonatomic, retain) NSArray *controllerNames;
 @property (nonatomic, retain) NSIndexPath *lastIndexPath;
+@property (nonatomic, retain) UITabBarController *tabController;
 
 -(void) dismissSplitView;
 
--- a/project_files/HedgewarsMobile/Classes/SettingsBaseViewController.m	Sat Oct 01 02:49:40 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SettingsBaseViewController.m	Sat Oct 01 03:06:51 2011 +0200
@@ -27,7 +27,7 @@
 #import "SupportViewController.h"
 
 @implementation SettingsBaseViewController
-@synthesize targetController, controllerNames, lastIndexPath;
+@synthesize tabController, targetController, controllerNames, lastIndexPath;
 
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
@@ -120,11 +120,11 @@
             releaseAndNil(navController);
         }
 
-        UITabBarController *tabController = [[UITabBarController alloc] init];
-        tabController.viewControllers = tabBarNavigationControllers;
-        tabController.delegate = self;
+        self.tabController = [[UITabBarController alloc] init];
+        self.tabController.viewControllers = tabBarNavigationControllers;
+        self.tabController.delegate = self;
 
-        [self.view addSubview:tabController.view];
+        [self.view addSubview:self.tabController.view];
     }
     [doneButton release];
     [super viewDidLoad];
@@ -251,6 +251,8 @@
         schemeSettingsViewController = nil;
     if (supportViewController.view.superview == nil)
         supportViewController = nil;
+    if (tabController.view.superview == nil)
+        tabController = nil;
     MSG_MEMCLEAN();
     [super didReceiveMemoryWarning];
 }
@@ -258,6 +260,8 @@
 -(void) viewDidUnload {
     self.controllerNames = nil;
     self.lastIndexPath = nil;
+    self.targetController = nil;
+    self.tabController = nil;
     generalSettingsViewController = nil;
     teamSettingsViewController = nil;
     weaponSettingsViewController = nil;
@@ -271,6 +275,7 @@
     releaseAndNil(targetController);
     releaseAndNil(controllerNames);
     releaseAndNil(lastIndexPath);
+    releaseAndNil(tabController);
     releaseAndNil(generalSettingsViewController);
     releaseAndNil(teamSettingsViewController);
     releaseAndNil(weaponSettingsViewController);
--- a/project_files/HedgewarsMobile/Classes/SettingsContainerViewController.h	Sat Oct 01 02:49:40 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SettingsContainerViewController.h	Sat Oct 01 03:06:51 2011 +0200
@@ -21,11 +21,15 @@
 
 #import <UIKit/UIKit.h>
 
+@class SettingsBaseViewController;
+
 @interface SettingsContainerViewController : UIViewController {
+    SettingsBaseViewController *baseController;
     UINavigationController *activeController;
     UISplitViewController *splitViewRootController;
 }
 
+@property (nonatomic,retain) SettingsBaseViewController *baseController;
 @property (nonatomic,retain) UINavigationController *activeController;
 @property (nonatomic,retain) UISplitViewController *splitViewRootController;
 
--- a/project_files/HedgewarsMobile/Classes/SettingsContainerViewController.m	Sat Oct 01 02:49:40 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SettingsContainerViewController.m	Sat Oct 01 03:06:51 2011 +0200
@@ -24,7 +24,7 @@
 #import "CommodityFunctions.h"
 
 @implementation SettingsContainerViewController
-@synthesize activeController, splitViewRootController;
+@synthesize baseController, activeController, splitViewRootController;
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     return rotationManager(interfaceOrientation);
@@ -59,10 +59,15 @@
         // add view to main controller
         [self.view addSubview:self.splitViewRootController.view];
     } else {
-        SettingsBaseViewController *baseController = [[SettingsBaseViewController alloc] init];
-        baseController.targetController = nil;
-        baseController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
-        [self.view addSubview:baseController.view];
+        if (nil == self.baseController) {
+            SettingsBaseViewController *sbvc = [[SettingsBaseViewController alloc] init];
+            self.baseController = sbvc;
+            [sbvc release];
+        }
+        self.baseController.targetController = nil;
+        self.baseController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
+
+        [self.view addSubview:self.baseController.view];
         // here setting activeController is not needed as the event is kept active by the uitabbarcontroller
     }
 
@@ -72,15 +77,18 @@
 #pragma mark -
 #pragma mark Memory management
 -(void) didReceiveMemoryWarning {
+    if (self.baseController.view.superview == nil)
+        self.baseController = nil;
+    if (self.activeController.view.superview == nil)
+        self.activeController = nil;
     if (self.splitViewRootController.view.superview == nil)
         self.splitViewRootController = nil;
-    if (self.activeController.view.superview == nil)
-        self.activeController = nil;
     MSG_MEMCLEAN();
     [super didReceiveMemoryWarning];
 }
 
 -(void) viewDidUnload {
+    self.baseController = nil;
     self.activeController = nil;
     self.splitViewRootController = nil;
     MSG_DIDUNLOAD();
@@ -88,6 +96,7 @@
 }
 
 -(void) dealloc {
+    releaseAndNil(baseController);
     releaseAndNil(activeController);
     releaseAndNil(splitViewRootController);
     [super dealloc];