I neglected to send this to the list. It's important enough that I think I 
should.

Bill Cheeseman

Begin forwarded message:

> From: Bill Cheeseman <wjcheese...@gmail.com>
> Subject: Re: Analyser reports memory leak… where?
> Date: September 12, 2013 6:34:05 AM EDT
> To: Graham Cox <graham....@bigpond.com>
> 
> The -eventTypes method sends the -setEventTypes: message, which retains the 
> object and assigns it to the mEventTypes iVar. Then -eventTypes returns the 
> mEventTypes iVar without autoreleasing it, and -eventTypes doesn't have 
> "new", "copy", or whatever in its name. The release of the eventTypes local 
> variable in -eventTypes only offsets the first retain implicit in the -alloc 
> message in -newEventTypes. The retain count is still +1 at the point where 
> the error is reported.
> 
> Bill Cheeseman
> 
> On Sep 12, 2013, at 5:35 AM, Graham Cox <graham....@bigpond.com> wrote:
> 
>> Here's some code for which the Analyser reports "potential leak of an object 
>> stored into 'eventTypes'". I don't see it.
>> 
>> I didn't write this code, so I'm reluctant to change it even though I would 
>> have written it a bit differently. mEventTypes is an ivar.
>> 
>> - (void)setEventTypes:(NSDictionary*)eventTypes
>> {
>>      if (eventTypes != mEventTypes)
>>      {
>>              [mEventTypes release];
>>              mEventTypes = [eventTypes retain];
>>      }
>>      InitializePrefsForEventTypeNames();
>> }
>> 
>> - (NSDictionary*)eventTypes
>> {
>>      if (mEventTypes == nil)
>>      {
>>              [self loadNib];
>>              
>>              NSDictionary* eventTypes = [self newEventTypes];
>>              [self setEventTypes:eventTypes];
>>              [eventTypes release];
>>      }
>>      
>>      return mEventTypes;     //<----- analyser complains here
>> }
>> 
>> 
>> 
>> - (NSDictionary*)newEventTypes
>> {
>>      //[code deleted that presets contents of 'eventTypes']
>> 
>>      // Method name begins with "new"; clients are responsible for releasing.
>>      return [[NSDictionary alloc] initWithDictionary:eventTypes];
>> }
>> 
>> 
>> 
>> --Graham
>> _______________________________________________
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> 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:
>> https://lists.apple.com/mailman/options/cocoa-dev/wjcheeseman%40gmail.com
>> 
>> This email sent to wjcheese...@gmail.com
> 
> -- 
> 
> Bill Cheeseman - b...@cheeseman.name
> 

-- 

Bill Cheeseman - b...@cheeseman.name

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to