Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 14, 2006, 01:02 PM   #1
AlmostThere
macrumors 6502a
 
Join Date: Feb 2005
Location: The royal throne of kings, the sceptred isle, the other Eden, the fortress built
MallocDebug

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:
Code:
#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

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
__________________
Join the army of the dead: http://www.urbandead.com
AlmostThere is offline   0 Reply With Quote
Old Mar 14, 2006, 08:49 PM   #2
iSee
macrumors 68030
 
iSee's Avatar
 
Join Date: Oct 2004
I ran into this same problem once. I left it alone (I don't write code with leaks anyway ) but I did find a potential solution.

Look here: http://developer.apple.com/documenta...gingMemory.pdf

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...
iSee is offline   0 Reply With Quote
Old Mar 15, 2006, 03:50 AM   #3
AlmostThere
Thread Starter
macrumors 6502a
 
Join Date: Feb 2005
Location: The royal throne of kings, the sceptred isle, the other Eden, the fortress built
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.
__________________
Join the army of the dead: http://www.urbandead.com
AlmostThere is offline   0 Reply With Quote
Old Mar 15, 2006, 09:41 AM   #4
iSee
macrumors 68030
 
iSee's Avatar
 
Join Date: Oct 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.
iSee is offline   0 Reply With Quote
Old Mar 15, 2006, 10:14 AM   #5
AlmostThere
Thread Starter
macrumors 6502a
 
Join Date: Feb 2005
Location: The royal throne of kings, the sceptred isle, the other Eden, the fortress built
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.
__________________
Join the army of the dead: http://www.urbandead.com
AlmostThere is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 06:33 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC