I use the following code:
int main()
{
int* foo = new int[10];
foo = nullptr;
sleep(60);
}
I build it inside XCode 7.2 and run instruments to see memory leak. I changed time delay differently and changed Instruments checking delay (from 10 to 2 sec). I tried to build project differently (Release, Debug) and also I tried to avoid compiler optimization:
int* foo = new int[10];
for (int i = 0; i < 10; ++i)
{
foo[i] = i*3 + i^2;
}
for (int i = 0; i < 10; ++i)
{
cout << foo[i] << endl;;
}
foo = nullptr;
sleep(60);
but I still can't see any leak inside Instruments/leak bars. What I do wrong?
Upd: I found a workaround, if I stop my console app at breakpoint and then, from the console, run
MacBook-Pro-andrey-2:~ owl$ leaks Ctrain
Process: Ctrain [30305]
Path: /Users/owl/Library/Developer/Xcode/DerivedData/Ctrain-cuhszmbcsswlznetmyijwykgudlz/Build/Products/Debug/Ctrain
Load Address: 0x100000000
Identifier: Ctrain
Version: ???
Code Type: X86-64
Parent Process: debugserver [30306]
Date/Time: 2015-12-23 21:30:28.768 +0300
Launch Time: 2015-12-23 21:30:25.837 +0300
OS Version: Mac OS X 10.10.5 (14F27)
Report Version: 7
Analysis Tool: /Applications/Xcode.app/Contents/Developer/usr/bin/leaks
Analysis Tool Version: Xcode 7.2 (7C68)
----
leaks Report Version: 2.0
Process 30305: 390 nodes malloced for 34 KB
Process 30305: 1 leak for 48 total leaked bytes.
Leak: 0x1001054f0 size=48 zone: DefaultMallocZone_0x10006e000
0x00000002 0x00000006 0x0000000a 0x0000000e ................
0x00000012 0x00000016 0x0000001a 0x0000001e ................
0x00000022 0x00000026 0x93554c2c 0x00007fff "...&...,LU.....
but it is just workaround and not the answer why Instruments can't catch this leak (or any leak in my case).