Re: (void *)contextInfo
Re: (void *)contextInfo
- Subject: Re: (void *)contextInfo
- From: Sherm Pendley <email@hidden>
- Date: Tue, 12 Jan 2010 15:04:25 -0500
On Tue, Jan 12, 2010 at 2:51 PM, Rainer Standke <email@hidden> wrote:
>
> Here is the code that displays the sheet:
>
> NSArray *theContextInfo = [[NSArray alloc] init];
This creates a new array that you are responsible for releasing when
you're finished with it.
> theContextInfo = [NSArray arrayWithObject:objTBD];
This creates a new array that you are *not* responsible for releasing.
Because you assign the result to theContextInfo without releasing the
previous array, that one leaks. Because you expect to use the new
array later, you should have retained it.
> What am I missing? (Another newbie thing I suspect...)
The memory management guidelines:
<http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html>
Additionally, I'd recommend making theContextInfo into an instance
variable, rather than passing it through the contextInfo. You can then
write (or @synthesize) an accessor method that encapsulates all of the
relevant memory management into one place, which is *far* less
error-prone than scattering -retain and -release calls all over the
place.
sherm--
--
Cocoa programming in Perl:
http://www.camelbones.org
_______________________________________________
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