I have two classes A and B. In A, I am creating an object of B, and in B I am accessing the back Button property of class A. In B, I have declared A as a weak reference variable. The code runs fine without any crash. However I am not sure if there is memory leak occurring in my implementation. Also, do I have to declare backButton as a weak reference in A ?
@interface A : UIViewController
{
IBOutlet UIButton *backButton;
B * cntrl;
}
@property (nonatomic, strong) UIButton *backButton;
// Here is the implementation of A
@implementation A
@synthesize backButton;
// pushing to B
cntrl = [[B alloc]initWithNib:nil bundle:nil];
cntrl.parent = self;
[self.navigationController pushViewController:cntrl animated:YES];
@interface B:UIViewController
{
A __weak *parent;
}
@implementation
-(void)method
{
parent.backButton.enable = NO;
[self.navigationController popViewControllerAnimated:YES];
}
No, your code is fine.
If you have any doubt, you can test your app with instruments.