sujith1406
sujith1406

Reputation: 2822

how to fix this memory leak?

- (void)addChild:(MyTreeNode *)newChild {
    newChild.parent = self;
    [self checkForSelectedNode:newChild];
    [self.children addObject:newChild];

}

In this code children is a property of the class used.The line [self.children addObject:newChild];

is showing 100 % leak when debugging with instruments. it is properly released in the dealloc method.still it is showing leak.how to remove this leak?

Upvotes: 1

Views: 87

Answers (1)

zaph
zaph

Reputation: 112857

In the header of MyTreeNode the parent property should be assign not retain. Other wise there are retain cycles and memory leaks.

Explanation: Down one level the node is retaining it's parent and the parent is retaining it's child. This retain cycle will keep itself from releasing.

Upvotes: 2

Related Questions