Discussion in 'Mac Programming' started by AlmostThere, Mar 14, 2006.

  1. AlmostThere macrumors 6502a

    As straight to the point as I can be, trying to move over more and more to OS X from Linux, I could do with a quick pointer (ho, ho) to get started with the Apple tools.

    Allocate, fill and leak some memory:
    #include <iostream>
    #include <algorithm>
    int main (int argc, char * const argv[]) 
        char *block = new char[100];   
        std::fill(block, block+100, 'z');  
        block[0]     = 'a';                    
        return 0;                               
    Build then Debug -> Launch with Performance Tool -> MallocDebug
    results in a minute or two of spinning rainbow wheel followed the dialogue:

    Read Data
    Unable to read malloc information from /Path/To/Project/Debug/executable

    Building from the command line with -lMallocDebug and loading the programme manually gives the same result and loads of multiple definition warnings.

    Surely there is something trivial I am missing :confused:

    Are there any other tools worth checking out? Under Linux I have been using valgrind, pretty much since it was released, which frankly has been the bees knees.

    Reference MallocDebug at Apple
  2. iSee macrumors 68040


    Oct 25, 2004
    I ran into this same problem once. I left it alone (I don't write code with leaks anyway :rolleyes: ) but I did find a potential solution.

    Look here:

    at around page 29, in the "Running Under libMallocDebug" section. It seems to describe your situation and what to do about it.

    I never actually tried this though, so I don't know if this is really the solution. Anyway, if you don't get a more concrete suggestion, you could give it a try...

    good luck...
  3. AlmostThere thread starter macrumors 6502a

    Apparently you should almost never need to link to libMallocDebug. Setting the relevant environment variables does show memory aloocation logging in Terminal but still no joy in trying to use MallocDebug from the GUI.

    Nice to have all that information in one place though.
  4. iSee macrumors 68040


    Oct 25, 2004
    Sorry that last idea wasn't helpful.

    One more thing, though: MallocDebug works by watching a running app. The example app you show executes, finishes and terminates almost immediately. MallocDebug may not be able to attach to it before it finished what it's doing and quits. If you are looking for the type of leak checker that logs what's happening and can give you a report after execution is complete, I don't think MallocDebug is it anyway. I didn't see any logging functions anyway.
  5. AlmostThere thread starter macrumors 6502a

    Yeah, I am rather under than impression. I just kind of feel there should be a good OS X tool that fits the bill. I come back to look at this issue every 18 months or so ... but never seem to be able to track down definitive answers, or more importantly worked examples. So I stuck about the most simple thing I could think of and wondering how to show the error on OS X, rather assuming MallocDebug would be the tool to use.

    It has just cropped up again now partly because repeated allocation (that made development much quicker) has now turned into major a bottle neck and also after chatting with another Linux using friend about using Macs / Unix etc. and the tools available, differences and such like.

    Anyway, thanks for the input. Will go over the PDF in greater detail sometime soon.

Share This Page