iphone : Passing objects between functions
my code is like this
- (id)getViewControllerForManagedObject:(QIManagedObject *)object {
DataTableViewControllerReports *nextControllerReports = [[[DataTableViewControllerReports alloc] initWithNibName:@"ReportsScreenXIB" bundl开发者_如何学Ce:nil] autorelease];
nextControllerReports.objectStack = [self.objectStack arrayByAddingObject:object];
return nextControllerReports;}
I am returning the auto release object to function declared in parent class. but at this point m app crashes. I ran the application in debug mode and i found that after returning from this function it shows "Objc_Msgsend". Means the nextcontrollerReports object is getting released. So any one can help me to pass this object to other function.
Thanks in advance.
add retain to the returned object immediately after calling this function and see..
You should not set nextControllerReports to autorelease, because it will cause the runtime to relase memory as soon as it can.
Then you will get a warning, because the caller of this method will retain the memory allocation of the returned object, and this is not understandable from the name of your method. To remove it you should rename the method to something that start with copy|alloc|init.
To avoid leaks, the caller of the method have to release the object when it can.
精彩评论