user970251
user970251

Reputation: 355

Instruments not able to find a memory leak

I have this test code which i run using Profile options. But I am not able to see any leaks

I have 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;
}

Upvotes: 0

Views: 779

Answers (1)

zaph
zaph

Reputation: 112857

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.

Upvotes: 1

Related Questions