PDA

View Full Version : How Do You Enable Memory Leak Detecting In Xcode?




bobber205
Apr 26, 2007, 12:30 AM
In Visual studio you use:


#define _CRTDBG_MAP_ALLOC

//then after main
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);



This does not compile in Xcode.
Launch Using Performance Tool --> Malloc does not work b/c I am using the new operators with C++.

EDIT:

When I purposely try to go over an array's bounds, I get "executable path is nil". What does this mean?

Thanks! :D



kpua
Apr 26, 2007, 09:57 AM
Those flags are definitely a Windows or Visual Studio only feature.

As far as debugging memory leaks on a Mac, take a gander at this:

http://www.cocoadev.com/index.pl?MemoryLeaks

Some of it is Cocoa/Objective-C specific, but a lot of it isn't.

GothicChess.Com
Apr 26, 2007, 10:57 AM
In Visual studio you use:


#define _CRTDBG_MAP_ALLOC

//then after main
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);



This does not compile in Xcode.
Launch Using Performance Tool --> Malloc does not work b/c I am using the new operators with C++.

EDIT:

When I purposely try to go over an array's bounds, I get "executable path is nil". What does this mean?

Thanks! :D


I am not sure what you mean by "Malloc does not work..."

malloc() almost always works if you have enough RAM to support what you are malloc-ing! Are you trying a data type conversion on what you are malloc-ing, or just asking for a chuck of memory?

Trying to create range-checking errors on purpose is not a sign of bravery... that is usually the quickest way to crash, do not "Pass Go" or collect $200, go straight to Crash City, enjoy your stay...

I work with malloc() day in and day out, so if I knew more about what you were trying to do, I might be able to help.

bobber205
Apr 26, 2007, 09:21 PM
I didn't mean the Malloc function in general. ;)

I meant the Tool That's called MallocCheck or something like that. :D

gnasher729
Apr 27, 2007, 06:16 AM
Could I suggest that instead of asking the poor folks at MacRumors you get the information from the horses mouth?

Go to www.apple.com.
Click on "Developer"
Type "memory leak" into the search box.

Krevnik
Apr 27, 2007, 02:59 PM
I didn't mean the Malloc function in general. ;)

I meant the Tool That's called MallocCheck or something like that. :D

If I recall correctly, the new operator calls into malloc() at some point, so MallocCheck should still work.

Catfish_Man
Apr 27, 2007, 09:29 PM
That matches with what I remember as well.

Thomas Harte
Apr 28, 2007, 07:22 AM
Are you looking for Guard Malloc? To enable it, just tick "Enable Guard Malloc" at the bottom of the Debug pull-down menu in the menu bar. Then do a "Build and Debug" (i.e. command+Y) from the build menu...