5
votes

I am newbie here. i am trying to build a quiz app and while my app runs fine for the first iteration of the quiz it exits without any console errors on the second run. PAsting all the code below for reference.

It seems like when i re-run the quiz, -(void) loadNextWord function below does execute but nothing happens after that.

Please help!

Thank you!

Dump from the debugger:

My line 14 in main func is int retVal = UIApplicationMain(argc, argv, nil, nil);

#import <UIKit/UIKit.h>

 int main(int argc, char *argv[]) {

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}

Program received signal:  “EXC_BAD_ACCESS”.
(gdb)
#0  0x025f0907 in objc_msgSend ()
#1  0x05f28da0 in ?? ()
#2  0x023cfc9d in _CFAutoreleasePoolPop ()
#3  0x0001ee67 in -[NSAutoreleasePool release] ()
#4  0x002cfe7f in _UIApplicationHandleEvent ()
#5  0x02d73822 in PurpleEventCallback ()
#6  0x02474ff4 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#7  0x023d5807 in __CFRunLoopDoSource1 ()
#8  0x023d2a93 in __CFRunLoopRun ()
#9  0x023d2350 in CFRunLoopRunSpecific ()
#10 0x023d2271 in CFRunLoopRunInMode ()
#11 0x02d7200c in GSEventRunModal ()
#12 0x02d720d1 in GSEventRun ()
#13 0x002d3af2 in UIApplicationMain ()
#14 0x00002880 in main (argc=1, argv=0xbfffef94) at /Users/vbhardwaj/Documents/ObjectiveC/FinalProject/FunWords/main.m:14
2
Looks like you may have misspelled dealloc there...Jacob Relkin
Hi Jacob - It's fixed in code, got misspelled in formatting. that doesn't seem to to be the issue. . .Vatsal Bhardwaj
Have you tried running in Debug mode? Select Debug configuration and start with debugger attached. The console should give a good hint or stop right away at the correct line.Eiko
Thanks Eiko! I just inserted the dump from debugger. It's pointing to main.m (which i haven't even touched as part of this project). the line it's complaining about is int retVal = UIApplicationMain(argc, argv, nil, nil);Vatsal Bhardwaj

2 Answers

8
votes

Looking at the stack trace you see the line

[NSAutoreleasePool release]

This tells me that you have released an object too many times i.e. something like :

NSString *string = [NSString stringWithString:@"Hello"]; // This string is autoreleased
[string release]; // This line won't crash but is WRONG!

The above code will not crash immediately but the string will be released and dealloc'd. However, because it's also autoreleased the autorelease pool will try to release it again at some point in the future. You don't know when and will get a random crash.

You've probably done something like that :)

0
votes

The problem is with multiple-releases.

To be able to properly debug your code, even include files are nessasary. I can see that you are releasing wordImageView in your code. You shouldn't do that. What you should do is to take advantage of properties and do something like

self.wordImageView = nextImageView;
[nextImageView release];

instead of

[wordImageView release]; // release the flagView's memory
wordImageView = nextImageView; // reassign flagView to the new view

You can always use autorelease pools too, but this comes with memory penalty issues.

Btw, although the problem seems to be in the main loop, it isn't there. That is only the location of where the autorelease pool is cleaned, and the problem appears.

In any case, probably have a look at your code and make sure all 'alloc' is handled by a 'release' of the same object inside the same selector.