• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CFPreferences and init.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFPreferences and init.


  • Subject: Re: CFPreferences and init.
  • From: "Kyle Sluder" <email@hidden>
  • Date: Sun, 26 Oct 2008 21:31:47 -0400

On Sun, Oct 26, 2008 at 7:39 PM, Adam R. Maxwell <email@hidden> wrote:
>
> On Oct 26, 2008, at 2:47 PM, Kyle Sluder wrote:
>
>> And I've already noticed a memory management error in my own code;
>> -setServers: leaks the old array.  The first lines of the -setServers:
>> method should look like this:
>>
>> -(void)setServers:(NSArray *)newServers
>> {
>>  NSArray *oldServers = servers;
>>  servers = [[newServers copy] retain];
>>  [oldServers release];
>>
>>  // ... the rest of the method ...
>> }
>
> This still leaks, since you copy the parameter and then retain the copy.

Yes it does, because -copy implicitly retains the sender.  My mistake.
 (That's why we disclaim Mail-written code, after all!)  So you can
remove the call to -retain:

-(void)setServers:(NSArray *)newServers
{
 NSArray *oldServers = servers;
 servers = [newServers copy];
 [oldServers release];

 // ... method continues...
}

--Kyle Sluder
_______________________________________________

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

  • Follow-Ups:
    • CFPreferences and init: a possible reason?
      • From: Adam Penny <email@hidden>
References: 
 >CFPreferences and init. (From: Adam Penny <email@hidden>)
 >Re: CFPreferences and init. (From: Adam Penny <email@hidden>)
 >Re: CFPreferences and init. (From: Jean-Daniel Dupas <email@hidden>)
 >Re: CFPreferences and init. (From: Adam Penny <email@hidden>)
 >Re: CFPreferences and init. (From: Adam Penny <email@hidden>)
 >Re: CFPreferences and init. (From: Adam Penny <email@hidden>)
 >Re: CFPreferences and init. (From: "Kyle Sluder" <email@hidden>)
 >Re: CFPreferences and init. (From: "Kyle Sluder" <email@hidden>)
 >Re: CFPreferences and init. (From: "Adam R. Maxwell" <email@hidden>)

  • Prev by Date: Re: CFPreferences and init.
  • Next by Date: Re: Newbie: Referencing Objects (second try)
  • Previous by thread: Re: CFPreferences and init.
  • Next by thread: CFPreferences and init: a possible reason?
  • Index(es):
    • Date
    • Thread