views:

244

answers:

2

hi...

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.

+1  A: 

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

Quakeboy
thanks, I did that and then it was working fine. But i think this way the object will leak, what do u say????
KK
Instead of retaining directly, assign it to a property defined as (nonatamic, retain) and add a call to release this property member in your class' dealloc
cidered
yes.. u can do like cidered says.. when u hold an object using retain.. u have to release it later..or set it as a property(with retain attribute) to something..
Quakeboy
Do Mark the answer if it solved the issue. thanks :)
Quakeboy
A: 

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.

sosergio