Hajdučák Marek
Hajdučák Marek

Reputation: 11

How can I detected memory leak's in Linux/MacOs platform?

I have prepare header file "heap_monitor.h". This header work that, if I include this on some other header file, its check me any memory leak in this header and cpp file. When i forget delete objects in destructor, they stay in heap and this monitor send me error, an I know where i don't delokate memory in heap.

#pragma once
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

#define new new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )

#define initHeapMonitor() _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF)

this version of code including crtdbg.h which is Windows library. In Xcode is code I don't compile with this error:

ERROR: 'crtdbg.h' file not found

I must wrote some other code to check this memory leaks or something to fix the program to compile my work without this.

when I delete crtdbg.h x code send me 20 errors in new.cpp: https://prnt.sc/iv1x7d

Know someone how I fix this problem ?

Upvotes: 1

Views: 2958

Answers (2)

Darokrithia
Darokrithia

Reputation: 160

http://valgrind.org/downloads/current.html Valgrind is the best method of finding memory leaks for mac c++ development.

Upvotes: 0

Netanel Gonen
Netanel Gonen

Reputation: 39

As far as I know, the best way to search for memory leaks is to use a tool named Valgrind just use the memcheck command. you can see details here: http://valgrind.org/docs/manual/mc-manual.html for macOS, you can see the thread Valgrind on macOS Sierra

Upvotes: 1

Related Questions