I have a class which is responsible and the owner of building my model objects. It allocates memory for the models and has them retained and is responsible for releasing them when dealloc happens.
Now I have a respective UIViewController which is acting as the client in this case. It will have several instance variables, pointing to the model(s) it needs. It doesn't need to allocate the memory for them as the class responsible for doing so has already done it. Do I still need to release the memory from the client? Here's an example
ModelHolder.m will have something like
- (NSArray *)modelA
{
if (modelA == nil) {
modelA = [[ModelClassA alloc] init];
}
return modelA
}
- (void)dealloc { [super dealloc]; [modelA release]; }
Now the ClientViewController will have something similar:
@class myModelA;
@interface ClientViewController : UIViewController {
ModelClassA myModelA;
}
// more code
@end
#import "ModelHolder.h"
@implementation ClientViewcontroller ...... etc
- (void)viewDidLoad
{
self.myModelA = [instanceOfModelHolder modelA];
}
- (void)dealloc {
// am I responsible to release here?
}
Please don't mind any syntactical errors as I just wrote this on the fly here. I think my point was illustrated fine in code though.
Thank you..