开发者

Instruments not able to find a memory leak

开发者 https://www.devze.com 2023-04-12 18:32 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消