I have a problem in one of my VCs called ArticleViewController. The dealloc method is never called, and when the view is opened and closed three times, there are three VCs alive.
I read here (great source when you have a retain cycle in your ViewController!) the following:
If you use
someObj.delegate = self;inside the view controller, check the delegate property on
someObjisweak.@property (nonatomic, weak) id delegate;
One of the snippets in my VC is:
PopViewController *pop=[[PopViewController alloc] initWithNibName:@"PopViewController" bundle:nil];
pop.delegate = self;
So I check in PopViewController.h if the property is weak.
@property (nonatomic, assign) id <PopViewControllerDelegate> delegate;
Since strong is the default, and there is no explicit weak here, would this cause my retain cycle? I am bit in doubt, because I see the same thing in the header file of e.g. UIPopoverController.h, which is in the UIKit.
@property (nonatomic, assign) id <UIPopoverControllerDelegate> delegate;
You should change it to
weak.assignis default for primitive types and should be used by primitive types.idis an object, so it should be eitherweakorstrong- in this caseweak, because you should not increase the reference counter.You can read more about
strong/weak/assignhere, great explanation as far as I've noticed: SOF question about ARC.Glad to see it's an important case for you as many people even not so new in Obj-C just 'skip' the problem and run into memory issues later.
-- edit --
Maybe you have any block inside and you're keeping a strong reference to self inside? Any dispatch or anything? Maybe you have property on another controller to this one and that's why it's still living?