Ravindra Bagale
Ravindra Bagale

Reputation: 17655

program received signal "EXC_BAD_ACCESS"

When I run this following code it gives above error

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


   self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    [self.window makeKeyAndVisible];

    self.viewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
    self.firstViewController=[[FirstViewController alloc]initWithNibName:nil bundle:nil];
    UINavigationController *localNavigationController=[[UINavigationController alloc]initWithRootViewController:self.viewController];
    self.navigationController=localNavigationController;
    [localNavigationController release];
    UINavigationController *localFistNavigationController=[[UINavigationController alloc]initWithRootViewController:self.firstViewController];
    self.firstNavigationController=localFistNavigationController;
    [localNavigationController release];
   NSArray *twoBars=[[NSArray alloc]initWithObjects:self.navigationController,self.firstNavigationController, nil];
    UITabBarController *localTAbBarController =[[UITabBarController alloc]init];
    [localTAbBarController setViewControllers:twoBars];
    self.tabBarController=localTAbBarController;
    [localTAbBarController release];
    [self.window addSubview:self.tabBarController.view];

        return YES;
}

if i run following code it runs well

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
         [self.window makeKeyAndVisible];

    self.viewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
    self.firstViewController = [[FirstViewController alloc] initWithNibName:nil bundle:nil];

    self.navigationController = [[UINavigationController alloc]
                                 initWithRootViewController:self.viewController];

    self.firstNavigationController=[[UINavigationController alloc]initWithRootViewController:self.firstViewController];
    NSArray *twoBars=[[NSArray alloc]initWithObjects:self.navigationController,self.firstNavigationController, nil];

    self.tabBarController=[[UITabBarController alloc]init];
    [self.tabBarController setViewControllers:twoBars];

       [self.window addSubview:self.tabBarController.view];



    return YES;

i not understood what is the difference between these. in first one i just created local variables & assigned those to properties. in later one directly used the properties. why it is giving the error- program recieved signal "EXC_BAD_ACCESS"

Upvotes: 1

Views: 763

Answers (4)

Vishal
Vishal

Reputation: 8256

I think in first one you releases some code and then after release you again that object like:

[localTAbBarController release]; this. So may be thats why you got error- program recieved

signal "EXC_BAD_ACCESS". in second one you nicely use your object no releases so its work

fine.

Upvotes: 2

Rajneesh071
Rajneesh071

Reputation: 31091

Just check this line.

self.firstNavigationController=localFistNavigationController;
  -->>  [localNavigationController release];  

It should be [localFistNavigationController release];

Upvotes: 0

Paras Joshi
Paras Joshi

Reputation: 20541

UPDATE:

hey i use your code, here you get BAD_ACCESS on this bellow line see..

[localNavigationController release];

just comment it and you have not BAD_ACCESS

Upvotes: 1

Ravindra Bagale
Ravindra Bagale

Reputation: 17655

i got my answer. because of releasing same objects more than one time, it happens. i have released [localNavigationController release]; two times. later it must be

[localFirstNavigationController release];

Upvotes: 0

Related Questions