3

an app I'm working on keeps crashing when run on the iPhone but not on the Simulator (although a warning is shown when run without symbolic malloc_error_break, but the app keeps working on the Sim)

I'm not manually releasing any string, instead, i use:

[[[NSString / NSMutableString alloc] init] autorelease]; 

(which I do all the time for other apps and have never given me a problem)

Now when I set malloc_error_break as a breakpoint I get:

2012-03-07 17:04:06.072 columns[15487:f803] *** -[CFString release]: message sent to deallocated instance 0x68c8210

With XCODE4 jumping to:

int main(int argc, char *argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");   >>> Thread 1
    [pool release];
    return retVal;
 }

I also have NSZombieEnabled when run on the simulator btw

If anyone can help me on how to debug this on XCODE 4 or point me to a tutorial online that would be much appreciated!

Regards

david

David Homes
  • 2,725
  • 8
  • 33
  • 53
  • Unfortunately yes. Re add them one by one until it crashes. – CodaFi Mar 07 '12 at 21:58
  • thank you CodaFi for bringing me back to the basics, since switching to xcode4 I hadn't had such problems so even finding again instruments (Profile now) was a struggle. Anyhow, it was the dumbest thing: NSString *nssql=[[NSString stringWithFormat:@"select * from EN where TYPE='%@' ORDER BY CAST(W as numeric) asc;",p.shape] AUTORELEASE]; – David Homes Mar 07 '12 at 22:17
  • In general, I would try to avoid autoreleasing objects. Manually manage memory wherever you can. – eric.mitchell Mar 07 '12 at 22:17
  • I shall post it as an answer then. – CodaFi Mar 07 '12 at 22:18

1 Answers1

4

Remove autorelease from your NSString methods and add them back in until it crashes (I guess this is the answer now, so...)

CodaFi
  • 43,043
  • 8
  • 107
  • 153
  • yes it's man, thanks! Although i only starting checking the convenience string firsts. – David Homes Mar 07 '12 at 22:20
  • I recommend transitioning to ARC, and if you ever need to go back, just set compile settings on each individual file to -fno-ObjC-ARC – CodaFi Mar 07 '12 at 22:24
  • Coda, the only thing restricting me from it is that i like supporting my apps from one OS version before the current upwards. ARC isn't available for iOS4 that I know. Let me know if i'm wrong – David Homes Mar 07 '12 at 23:04
  • ARC is absolutely available for iOS 4.x! Only the first iPhone doesn't support ARC, and the only problem is that weak references must be declared as assign, but other than that, it's a no brainer! – CodaFi Mar 07 '12 at 23:14
  • thanks for letting me know!, i thought ARC was there only for iOS5 devices, will use on next project (next month). – David Homes Mar 08 '12 at 08:53