1

I am currently programming a iPhone-app for my maturity research. But there is an behavior I don't understand: Sometimes when i compile my project there is:

Thread 1: Program received signal : "EXC_BAD_ACCESS".

But when I compile the same code a second, or a third time the code just runs fine and i can't get why. I use some MonteCarloSimulation but when it fails it fails executing one of the first 100 simulations. But when every thing runs fine it executes 1000000 simulations without an error.. Really strange isn't it?

Do you have any idea? Can this be an issue of Xcode or arc? All other things just work perfect. Do you have to get any further information? I can also send you my code as an email.

Robin des Bois
  • 355
  • 2
  • 6
  • 20
  • you could do a search on Google or even here on [so] for `EXC_BAD_ACCESS` and find dozens, if not hundreds, of other similar reports and ideas on how to track down your issue. – Michael Dautermann Dec 09 '11 at 20:52

2 Answers2

1

This usually means you're trying to access an object that has already been deallocated.

In order to debug these things, Objective C uses something called "NSZombie" that will keep those objects around so you can at least see what it is that's trying to be called. See this question for some details on how to use it.

Community
  • 1
  • 1
Sean McMains
  • 57,907
  • 13
  • 47
  • 54
  • Thanks for the answer. I am using the ARC-mode. What are the things I have to mind? Is it possible to create an instance with a reference, that never will be destroyed in ARC-Mode? And if the answer is 'yes', can you explain me and make an example.. thanks a lot! – Robin des Bois Dec 09 '11 at 22:14
  • Found the solution.. I passed method an impossible argument.. I don't exactly know why it worked sometimes but now it works every time.. And I know how to make a singeltone in ARC-Mode.. thanks a lot to every one! – Robin des Bois Dec 10 '11 at 12:47
0

This is typically caused by accessing some memory that's been corrupted, chances are you have a reference to an object which has been deleted. A lot of the time you may find that the memory where the object was located has not yet been overwritten, so when you attempt to access that memory your data is still intact and there is no problem, hence it working some of the time.

Another scenario would be that you've got some code writing into memory using a bad reference, so you're writing into an area you shouldn't be. Depending on the memory layout when the program starts, this could have no effect some of the time but cause something catastrophic at other times.

Matt Lacey
  • 8,227
  • 35
  • 58