Xcode 4 memory problem

Discussion in 'Mac Programming' started by farmerdoug, Dec 10, 2011.

  1. macrumors 6502a

    Sep 16, 2008
    I get a "Thread 1: Program received signal: :EXC_BAD_ACCESS" error whenever I run too many conditions in a for loop. I suspect this is a memory problem; I have checked my memory allocation and freeing of memory buffers but of course could have missed something. What is the easy way for a hacker like me to debug this?

  2. macrumors 68000

    Mar 29, 2009
    Start out by posting the code that is giving you the error.
  3. thread starter macrumors 6502a

    Sep 16, 2008
    Let's not go there. The code is somewhat proprietary and beside the point.
    I should have just said what are good ways to look for what seem to be errors related to memory.


    Does anybody know anything about valgrind or memwatch? Is of them better or easier to use?
  4. macrumors G4


    Jun 6, 2003
    Solon, OH
    Lots of open-source projects use Valgrind to find and fix memory-related problems. I'd imagine that closed-source projects make use of it too. The key to using it is integrating it into your build process, to find these bugs BEFORE they make it to release-level code. As for Memwatch, I've not heard of this tool before.
  5. thread starter macrumors 6502a

    Sep 16, 2008
    Thanks. I'll probably give it a try. I've used memwatch with makefiles but seem to remember having trouble implementing it.
  6. macrumors 68030


    Dec 8, 2003
    Too many conditions? like..
    void foo(int x) {
        int *y = &x;
        for(y = 0; y < &x && *y == 1; y++) {
            (void) 0;
    Cause it runs fine (though it slowly) without the second compare.
    But in trying to make it speed up, I cause EXEC_BAD_ACCESS... :(

    Seriously though, if its repeatable every time, you're probably overflowing an array or something. Set break points earlier and earlier and just step through the code until your crash. You're probably dereferencing something you shouldn't, or overflowing an array due to poor control, or maybe having assignment when it should be comparison (= vs ==)
  7. thread starter macrumors 6502a

    Sep 16, 2008

Share This Page