EXC_BAD_ACCESS (code=1, address=0x0) when runModalForWindow
Solution 1
the best way to debug EXC_BAD_ACCESS
errors is to use NSZombies
.
Check out this video for an explanation :
NSZombie
keeps all your objects in memory when you are trying to release an object that has already been released, so you get closer to finding your bug. As @Mark H said, it is a memory management issue.
Also you could put an NSLog
in your dealloc method to have a better idea of what is getting deallocated when at runtime.
Solution 2
That error will be thrown when the object doesn't exist in memory. I'd start looking for memory management issues. The first would be to make sure you are releasing the ChooseProceduresWindowController after using it.
Radu Paise
Updated on June 05, 2022Comments
-
Radu Paise almost 2 years
I have a window and a window controller which opens when the user clicks a button. Sometimes I get EXC_BAD_ACCESS(code=1, address=0x0).
0x7fff6f2a59e0: movq (%rax), %rdi
Here is the code:
ChooseProceduresWindowController *chooseProceduresWindowController = [[ChooseProceduresWindowController alloc] initWithWindowNibName:@"ChooseProceduresWindow"]; [NSApp runModalForWindow:[chooseProceduresWindowController window]];
The error appears then runModalForWindow: is called. I don't get this error every time, but I couldn't find a pattern.
Thanks
-
Radu Paise almost 12 yearsI get the error before releasing, when I try to open it in modal.
-
Mark almost 12 yearsDo you open it multiple times and does it ever error out on the first try?
-
Radu Paise almost 12 yearsYes, I open it multiple times, and No, I didn't get the error on the first try.
-
Mark almost 12 yearsWhat does the code look like for releasing the allocated memory? Does it always get called?
-
Radu Paise almost 12 years[chooseProceduresWindowController release]; - just after the runForModal:
-
Mark almost 12 yearsI might be misunderstanding, but it seems like you are releasing the memory immediately after allocating it. Release the memory when you are done with the modal window.
-
Nico almost 11 years@MarkH:
runModalForWindow:
blocks until the modal event loop has been stopped or aborted (hopefully by the questioner's code in response to an action). -
Tim over 10 yearsI ran into this error when I tried releasing an alertView twice. (Still a noob at Objective-C)
-
Nicolas Miari about 10 yearsSometimes an object in the middle of being deallocated throws a "does not respond to selector" exception. And sometimes EXC_BAD_ACCESS is due to reading outside of the bounds of an array (seg fault), if I'm not wrong... But
NSZombies
is a good measure to start.