• 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: Should the analyzer catch retained objects returned from createXXX methods?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should the analyzer catch retained objects returned from createXXX methods?


  • Subject: Re: Should the analyzer catch retained objects returned from createXXX methods?
  • From: Bill Cheeseman <email@hidden>
  • Date: Wed, 17 Aug 2011 19:15:30 -0400


On Aug 17, 2011, at 5:22 PM, Ken Thomases wrote:

On Aug 17, 2011, at 4:06 PM, Rick Mann wrote:

I have a method named createFoo, from which I return an object with a retain count of 1. The Xc4 static analyzer is complaining about a potential leak, but I thought it would notice the "create" in the name...

"Create" in a name is a Core Foundation convention, not a Cocoa convention.  This is specifically called out in the Memory Management Programming Guide <http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html>:

Despite the fact that we all know the "create rule" is a Core Foundation naming convention, I have found that the Xcode 4 Analyzer depends on the presence of "create" or "copy" in a Cocoa method signature that returns a Core Foundation object to get memory management reporting right.

Here's how I figured it out. I have a framework that uses Cocoa methods to return Core Foundation objects. The leaks tool and the leaks instrument reported memory management problems in an application using my framework -- leaks. When I ran the Analyzer on it, it reported memory management issues that made no sense to me. I decided to try adding "create" and "copy" to method names that returned CFRetained Core Foundation objects, then ran the Analyzer again. This time it reported different memory management issues, and they made perfect sense to me. When I fixed the problems, the Analyzer no longer reported issues. To prove the point, I then ran the leaks tool and used Instruments to run its leaks instrument, and all my leaks were gone. QED.

So I think it is important to follow the "create rule" when naming Cocoa methods that return Core Foundation objects. This isn't documented, so I would certainly appreciate feedback from Apple engineers.

-- 

Bill Cheeseman - email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Should the analyzer catch retained objects returned from createXXX methods?
      • From: Christiaan Hofman <email@hidden>
References: 
 >Should the analyzer catch retained objects returned from createXXX methods? (From: Rick Mann <email@hidden>)
 >Re: Should the analyzer catch retained objects returned from createXXX methods? (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Any way to make code completion case-sensitive?
  • Next by Date: semi-stuck SYMROOT in project
  • Previous by thread: Re: Should the analyzer catch retained objects returned from createXXX methods?
  • Next by thread: Re: Should the analyzer catch retained objects returned from createXXX methods?
  • Index(es):
    • Date
    • Thread