How to find C or C++ code leaks using Instruments (Leaks) - Xcode?

做~自己de王妃 提交于 2019-12-04 15:40:09

The issue is that compiler will optimize out the call to new in the following code fragment:

int* foo = new int[10];
foo = NULL;
sleep(60);

as it's smart enough to know that it's not being used. If you add code to use foo then compiler won't do this and you should see the leak you are expecting:

int* foo = new int[10];

foo[3] = 23;
foo[8] = 45;

printf("%d %d\n", foo[3], foo[8]);

foo = NULL;
sleep(60);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!