• 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: Analyser reports memory leak… where?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Analyser reports memory leak… where?


  • Subject: Re: Analyser reports memory leak… where?
  • From: Graham Cox <email@hidden>
  • Date: Thu, 12 Sep 2013 17:52:20 +0200

On 12/09/2013, at 5:40 PM, Bill Cheeseman <email@hidden> wrote:

> But -eventTypes is not in fact a valid getter because it returns the iVar retained but not autoreleased.


How is it not valid?

A simple version of it would be:

- (id) eventTypes
{
     return mEventTypes;
}

which is perfectly valid. The rest of the code is just a lazy initialization for mEventTypes.


> The setter/getter convention requires getters to return autoreleased objects.

Not so, it requires that the returned object is not owned by the caller. That is all.


> So leaving it named according to the getter naming convention is wrong. Adding "new" would not only be correct but would also warn against using it as a getter.

But it is a getter, no more or less. The lazy initialization is neither here nor there to the caller.

> As written (no matter what it is named), it is in fact the caller's job to release it. That is presumably why you release it in -dealloc. If your class's -init method initially created the first object assigned to the iVar, whether by calling -eventTypes or by directly calling -newEventTypes and setting the iVar, then you are the owner and you must release it in -dealloc if not earlier. And if you call -eventTypes or -newEventTypes while substituting a new object for the old iVar object in midstream, you must release the old iVar object in midstream, too.


The object owns mEventTypes, so it is not the caller's job to release it. It is released in -dealloc because the object owns mEventTypes.

> At it's core, that's what is really "odd" about the code. It uses a getter that does not comply with the getter convention.

I believe it does. I think your reading of the getter convention may be incorrect. If you can point to explicit documentation that states that the returned object must belong to an autorelease pool, I'll stand corrected, but that would be the first time I've ever heard that in 13 years of Cocoa programming!

--Graham




_______________________________________________

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:
    • Re: Analyser reports memory leak… where?
      • From: Bill Cheeseman <email@hidden>
    • Re: Analyser reports memory leak… where?
      • From: Daniel Höpfl <email@hidden>
    • Re: Analyser reports memory leak… where?
      • From: Keary Suska <email@hidden>
References: 
 >Fwd: Analyser reports memory leak… where? (From: Bill Cheeseman <email@hidden>)
 >Re: Analyser reports memory leak… where? (From: Roland King <email@hidden>)
 >Re: Analyser reports memory leak… where? (From: Bill Cheeseman <email@hidden>)
 >Re: Analyser reports memory leak… where? (From: Graham Cox <email@hidden>)
 >Re: Analyser reports memory leak… where? (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: Re: Analyser reports memory leak… where?
  • Next by Date: Re: NSTabView
  • Previous by thread: Re: Analyser reports memory leak… where?
  • Next by thread: Re: Analyser reports memory leak… where?
  • Index(es):
    • Date
    • Thread