【发布时间】:2016-03-30 05:17:08
【问题描述】:
我使用以下代码:
int main()
{
int* foo = new int[10];
foo = nullptr;
sleep(60);
}
我在 XCode 7.2 中构建它并运行工具来查看内存泄漏。 我以不同的方式更改了时间延迟并更改了仪器检查延迟(从 10 秒到 2 秒)。我尝试以不同的方式构建项目(发布、调试),并且还尝试避免编译器优化:
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);
但我仍然看不到仪器/泄漏条内的任何泄漏。 我做错了什么?
更新:我找到了一种解决方法,如果我在断点处停止控制台应用程序,然后从控制台运行
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.....
但这只是解决方法,而不是为什么 Instruments 无法捕获此泄漏(或在我的情况下是任何泄漏)的答案。
【问题讨论】:
-
你见过this吗?
-
感谢您的评论,但我也已经尝试过了=( 使用函数调用和 { } 块
-
是的,我看到了那个帖子。我的时间延迟间隔大于仪器延迟
标签: c++ xcode memory-leaks