views:

350

answers:

3

I have an iphone app. It seems to run fine. When I connect to a provisioned iphone to Xcode and run the App, the console log in the Organizer window, always complains about a Segmentation fault when quitting the app with the home key.

Has anyone else seen this, and do you have an idea of what the problem might be? I use a thread to load web pages in the backround, but I stop the thread when exiting.

My app does save some persistent information. When I use the build and analyze function I get some 2 potential memory leaks, but in each case I'm allocating an object and keeping it in an array.

Any ideas, or is this normal?

A: 

Upon exit your application can over-release an object try dumping each object before releasing it or do some debugging in dealloc method.

Eimantas
A: 

Perhaps you are releasing some object more times than its retain count. Comment out -release calls in your dealloc methods (or elsewhere) until you find the culprit.

Then uncomment-out that call and look elsewhere in your code where you are trying to over-release that object.

If you are using convenience methods, for example, (e.g. [NSString stringWithFormat:@"..."]) as opposed to alloc-init methods (e.g. [[NSString alloc] initWithFormat:@"..."]) the resulting convenience object is autoreleased and should not be manually released.

Alex Reynolds
A: 

Try running your application with NSZombieEnabled. This will tell you if you're over releasing any object. To enable zombies do the following:

  1. Choose Project > Edit Active Executable to open the executable Info window.
  2. Click Arguments.
  3. Click the add (+) button in the “Variables to be set in the environment” section.
  4. Enter NSZombieEnabled in the Name column and YES in the Value column.
  5. Make sure that the checkmark forthe NSZombieEnabled entry is selected.
lyonanderson
With NSZombieEnabled, where should I set a breakpoint to catch the problem?With this setting, me program terminates early with the message: CFString autorelease: message sent to deallocated instance.I'd like to break when the message is sent to a deallocated string, so I can figure out which string.Thanks,Gerry
Gerry
With Zombies enabled. My code faults inside the [parser parse] line from the code below. This bit happens on an NSThread. Any ideas as to what would cause a problem. My foundCharacters routine is not hit.Thanks,Gerry (code in next comment)
Gerry
NSURL *nsurl = [NSURL URLWithString:query]; NSURLRequest *request = [NSURLRequest requestWithURL:nsurl]; data = [NSURLConnection sendSynchronousRequest:request returningResponse: NSXMLParser *parser = [[NSXMLParser alloc]initWithData:data]; [parser setDelegate:self]; [parser setShouldProcessNamespaces:NO]; [parser setShouldReportNamespacePrefixes:NO]; [parser setShouldResolveExternalEntities:NO]; errorStr = nil; if ( [parser parse] == YES ) // stuff
Gerry
I still don't have the complete answer. Running with NSZombies does cause an early crash in my program which should indicate a bug. The problem is that it happens in NSXMLParser which is outside of my control. Other multiple releases may persist, but I have to keep sectioning the code to find them. Sigh.
Gerry
lyonanderson