Program signal: "EXC_BAD_ACCESS"

I have a string variable that stores the date from a date set, but when I use its value in another function, I get an error, for example, the signal received by the program: "EXC_BAD_ACCESS". Note: the variable is defined globally.

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); } } 
+4
source share
2 answers

You must save this line. This is the most likely reason.

Edit: The only reason it crashes is a bad pointer. Bad pointer = release of object. Just run the application with zombies turned on, and you will see the place where you do it. Check out http://www.markj.net/iphone-memory-debug-nszombie/

+5
source

Whenever a failure occurs, send a back trace.

Before you do this, use “assembly and analysis” and fix any problems that it identifies.

After that, if it still works, then go through a Zombie detection pass and verify that you are re-issuing something (which most likely this code has an obvious issue with over-release as it is).

If it still crashes, then we will need to see more code ....

+3
source

Source: https://habr.com/ru/post/1341926/


All Articles