I have a class that is responsible and the owner of the objects of my model. He allocates memory for models and saves them and is responsible for their release when dealloc occurs.
Now I have a corresponding UIViewController that acts as a client in this case. It will have several instance variables, indicating the model (s) it needs. He does not need to allocate memory for them, since the class responsible for this has already done so. Do I still need to free memory from the client? Here is 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 ClientViewController will have something similar:
@class myModelA; @interface ClientViewController : UIViewController { ModelClassA myModelA; }
Please ignore the syntax errors as I just wrote this on the fly here. I think my point was illustrated in the code.
Thanks..
source share