• 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: Daniel Höpfl <email@hidden>
  • Date: Thu, 12 Sep 2013 17:45:23 +0200

On 2013-09-12 17:00, Bill Cheeseman wrote:
-eventTypes: is, in fact, a classic "new" method, though a bit oddly
written. All in the one method (by calls to utility methods), it
creates a new object with a refcount of 1 by calling +alloc
indirectly, increases its refcount by 1 more by calling
-setEventTypes:, decreases its refcount by 1 to balance the second
increase, and returns it with a refcount of 1 without autoreleasing
it. It does own the new object, and the method should have "new" in
its name.

I agree with Graham that the method must not be named new...
(because the caller is not to release the returned value).

I think there might be two reasons for the warning:

a) (I guess that not the reason): The analyser gets confused by
   seeing -setEventTypes:.

@Graham: What happens when you comment out the call to setEventTypes:?

      NSDictionary* eventTypes = [self newEventTypes];
      // [self setEventTypes:eventTypes];
      [eventTypes release];

Do you still get the warning?


b) The "if (mEventTypes == nil) {} return mEventTypes;" confuses the analyser:

   if (mEventTypes == nil)       // OK, mEventTypes might be nil here.
   {
[self loadNib]; // Might do anything, but due to the name: +/-0

NSDictionary* eventTypes = [self newEventTypes]; // +1 for eventTypes
      [self setEventTypes:eventTypes];// Might do anything,
// but due to the name: +/-0 for everything.
      [eventTypes release];           // -1 for eventTypes, fine.
   }

   return mEventTypes;
   // Wait. Why is the coder returning mEventTypes instead of nil?
// Nobody created an object, but the coder assumes that there is an object // in mEventTypes now. Where did it come from? It must not be autoreleased // because this would result in a dangling pointer, so it MUST be +1 (or more).
   // Might be a leak. Lets warn the coder.

Reasonable?

@Graham: Could you try the following:

- (BOOL)isEventTypesAvailable
{
   return mEventTypes != nil;
}

...
   if (![self isEventTypesAvailable])
   {
...

Bye,
   Daniel

@Bill: Sorry for sending this mail to you directly instead of to the list before. %-)
_______________________________________________

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


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>)

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