Memory allocation pattern related question
Memory allocation pattern related question
- Subject: Memory allocation pattern related question
- From: Daniel Luis dos Santos <email@hidden>
- Date: Sun, 29 Mar 2009 14:35:09 +0100
Hello,
I have a shared library and some client code. In the shared library I
am adopting the following method signature pattern :
- (int) someMethod: (aType*)someInParam anotherParam:
(aType**)someOutParam;
I use the return value to indicate success or failure in the execution
of the method, and the arguments to pass parameters in and out.
The out parameters are double pointers.
Also, the pattern I am using mandates that the out parameters
dereferenced values are allocated within the method. So :
- (int) someMethod: (aType*)someInParam anotherParam:
(aType**)someOutParam {
*aType = [[aType alloc] init];
return 0;
}
would do some logic and allocate the return value and set it to the
double pointer, that would be the visible on the calling scope.
My problem is that I am not really sure of the way Cocoa retains and
releases objects.
Using a global auto release-pool, when is the out param object
released ? At the end of the scope of someMethod ? or when I
explicitly release it ?
If the former, I have to retain it withing some method so that when
its scope finishes the ref count doesn't go to zero right ?
Since the idea is to continue using the return type throughout the
enclosing method call's scope how do I implement this safely so that I
don't end up trying to access release memory ?
Thanks
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden