• 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: LLVM : spurious memory-mgmt warnings with "Copy" methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LLVM : spurious memory-mgmt warnings with "Copy" methods


  • Subject: Re: LLVM : spurious memory-mgmt warnings with "Copy" methods
  • From: Christiaan Hofman <email@hidden>
  • Date: Wed, 14 Dec 2011 11:39:40 +0100


On Dec 14, 2011, at 7:42, Jens Alfke wrote:


On Dec 13, 2011, at 10:33 PM, Jerry Krinock wrote:

I think that Warning #1 is spurious because I'm releasing an object which was obtained from a 'Copy' method, which is correct.  And Warning #2 is spurious because the method has 'Copy' in its name, therefore returning a retained object is expected.

I think the rules are about methods whose names *begin* with “copy” or “mutableCopy”. So the static analyzer doesn’t recognize your methods as being copiers.


This is correct. It is true that the memory management rules documentation says 'contains "copy"',
but the documentation is wrong. Compare for instance -[NSArray initWithArray:copyItems:], which does not implicitly retain even though it contains "copy" in its name. (Somehow Apple does not agree with me on this very obvious and simple logic. And don't say copyItems is about the items, because the docs don't say that I should do some English linguistic analysis of the method names, and I am sure that the compiler also doesn't.)

So here is the relevant sentence in the docs as it *should* be:

You take ownership of an object if you create it using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy), or if you send it a retain message.

(I am not 100% sure there are not more "copy" variants, but this covers the behavior of every method in the standard Cocoa frameworks. And also the docs don't very clearly define the term "create" in this sentence; compare for instance the documentation on the method -newDocument: for some nice logical inconsistency/contradiction.)

As a general rule, when practice contradicts the documentation, than probably the documentation is wrong.

What is the correct way to fix these warnings?

Rename your methods to use the standard naming conventions, I think. Although I vaguely remember reading about some way to flag a method declaration to tell the compiler that it’s a copier (maybe a special __attribute type?)

—Jens

Always better to follow the (real) rules, especially when there is no good reason not to. And "the name doesn't sound very nice to me" is not a good (enough) reason.

Christiaan


 _______________________________________________
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: LLVM : spurious memory-mgmt warnings with "Copy" methods
      • From: Jerry Krinock <email@hidden>
References: 
 >LLVM : spurious memory-mgmt warnings with "Copy" methods (From: Jerry Krinock <email@hidden>)
 >Re: LLVM : spurious memory-mgmt warnings with "Copy" methods (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: LLVM : spurious memory-mgmt warnings with "Copy" methods
  • Next by Date: Re: LLVM : spurious memory-mgmt warnings with "Copy" methods
  • Previous by thread: Re: LLVM : spurious memory-mgmt warnings with "Copy" methods
  • Next by thread: Re: LLVM : spurious memory-mgmt warnings with "Copy" methods
  • Index(es):
    • Date
    • Thread