I have this test code which i run using Profile options. But I am not able to see any leaks
I h开发者_如何学编程ave injected a leak but not sure why instruments is not showing a leak
NSMutableArray* test_leak2()
{
int i=0;
NSMutableArray *arr = [[NSMutableArray alloc] init ];
while(i <100) {
NSImage *img = [[NSImage alloc] init ];
[arr addObject:img];
i++;
}
return arr;
}
int main(int argc, char *argv[])
{
NSMutableArray *arr = test_leak2();
return 0;
}
If you are using ARC there is no leak, ARC handles the retains/releases "under the covers".
The leaks tool is not foolproof, it is a good start.
The first line of defense if the Static Analyzer, run it and fix all warnings.
Not all losses of memory are leaks, just ones that there is no pointer to. Try Heapshot Analysis, bbum has a great tutorial here. I have used Heapshot many times to great advantage, many thanks to bum.
精彩评论