iphone - Allocation and release of a Class -
i have 1 controller class x has ibaction instance method dosomething.
i have other class y calculations , has delegate self.
in method dosomething instance of class y created. should instance of y released.is @property solution this.
//this action in class x
-(ibaction)dosomething:(id)sender {
y *y = [[y alloc]init];
//init method implemented in y , job delegates being called time time. if release y. crash. place release y. @property solution creating 1 time memory , using that. there way release here when next time other object created older have been destroyed before when delegates finishes job after time.//
//[y release]; crash.
}
you can 1 thing,
// in .h file // declare this. y *y; // in .m file -(ibaction)dosomething:(id)sender { if(y== nil) y = [[y alloc]init]; }
and in dealloc method, can release
- (void)dealloc{ [y release]; [super dealloc]; }
Comments
Post a Comment