KK.
KK.

Reputation: 1

iphone : Passing objects between functions

my code is like this

- (id)getViewControllerForManagedObject:(QIManagedObject *)object {

DataTableViewControllerReports *nextControllerReports = [[[DataTableViewControllerReports alloc] initWithNibName:@"ReportsScreenXIB" bundle: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.

Upvotes: 0

Views: 542

Answers (2)

sosergio
sosergio

Reputation: 964

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.

Upvotes: 0

Rajavanya Subramaniyan
Rajavanya Subramaniyan

Reputation: 2155

add retain to the returned object immediately after calling this function and see..

Upvotes: 1

Related Questions