I have a pretty weird problem in my iPhone app which is, I think, related to memory getting corrupted:
At one point, I need to sort an array, which I do with -[sortArrayUsingFunction]
.
The result is not correct unless I either allocate some memory with something like void *test = malloc(2 * sizeof( int ))
before the method call or have, e.g., a call to NSLog()
(which is never invoked) in the sorting function.
In other words: the sorting only works if I slightly increase the memory that was used before calling the sorting function. I think this is because at some point, memory gets corrupted.
How do you debug something like this?