Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program received signal: “EXC_BAD_ACCESS”

I have a string variable which stores date from date picker but when I use its value in other function I am getting error like Program received signal: “EXC_BAD_ACCESS”. Note: variable is globally defined.

code :

    - (void) changedDate: (UIDatePicker *) picker 
    {
     if (appDelegate.dateint == 8)
     {
     NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 

[dateFormatter setDateFormat:@"dd MMM, yyyy"];
     datestr=[dateFormatter stringFromDate:[dptpicker date]]; 
    NSLog(@"date:%@",datestr); 
    } 
    else if(appDelegate.dateint == 9) 
    { NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 

[dateFormatter setDateFormat:@"dd MMM, yyyy"]; 
    datestr1=[dateFormatter stringFromDate:[dptpicker date]] ;
     NSLog(@"date1:%@",datestr1);
     } 
    }
like image 261
Harshal Avatar asked Feb 24 '23 22:02

Harshal


1 Answers

You have to retain that string. This is the most likely reason.

Edit: The only reason why it is crashing is the bad pointer. The bad pointer = over-releasing the object. Just run your app with zombies enabled and you'll see the place where you're doing that. Check this http://www.markj.net/iphone-memory-debug-nszombie/

like image 152
Max Avatar answered Mar 06 '23 15:03

Max