1

I am trying to test the retain cycle in Xcode 6. I Write 2 class, one is TTChild and another is TTParent. The header file of them are as follows.

@interface TTParent : NSObject
@property (nonatomic,strong) NSMutableArray *children;
@end

@interface TTChild : NSObject
@property (nonatomic,strong) TTParent *parent;
@end

And in the viewController class, I add one button, in the action method, I write the following code.

- (IBAction)ClickMe:(id)sender {

    TTParent *parent = [[TTParent alloc] init];
    parent.children = [[NSMutableArray alloc] init];
    for (int i = 0; i < 1000; i++) {
        TTChild *child = [[TTChild alloc] init];
        child.parent = parent;
        [parent.children addObject:child];
    } 
}

This code can lead to memory leak. The Child and Parent make the retain cycle.When I test it in the Xcode 6 leaks instrument, I click the button several times. And I saw the red line in the leaks area. Then I select the Leaks-> Cycles&Roots->Leaks cycle. But in the Graph column, there is nothing. It should have some graph to show the retain cycle situation, doesn't it? Can someone explain this question, if it should not, then in which situation will the Graph show. If someone can help me, thanks in advance.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
Jay
  • 113
  • 1
  • 11
  • Yeah, I've never found the graph useful/reliable. I always use the call tree (generally inverting it and hiding system libraries). That process finds leaks in code pretty quickly. – Rob Aug 20 '15 at 15:01
  • Do you know how to make the graph view to be shown please? Is it that it will only be shown in special cases or in a difficult retain cycle? – Jay Aug 20 '15 at 15:20

0 Answers0