I’m working with creating my own custom view templates programmatically for the app I’m working on. To achieve this i have a custom view controller MyVC with a a custom view myView added on to it which is a property of MyVC. The class looks something like this:
MyVC.h
#import <UIKit/UIKit.h>
@interface MyVC : UIViewController{
MyCustomView *myView;
}
@property(nonatomic, retain) MyCustomView *myView
@end
In the implementation i want to assign a background color to ‘myView’ and i do something like this in the viewDidLoad (after synthesizing my property of corse)
-(void)viewDidLoad{
self.myView = [[MyCustomView alloc] initWithFrame:someFrame];
self.myView.backgroundColor = [UIColor clearColor];
}
Now when i analyze my code i get a ‘potential leak of an object’ message when i assign the color. Is it because myView or the background color or both are being retained?
In any case id like to know how this can be done correctly without potential leaks?
If you don’t using ARC you should release over retained property: