• 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: Why do CFType instances respond to NSObject messages?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why do CFType instances respond to NSObject messages?


  • Subject: Re: Why do CFType instances respond to NSObject messages?
  • From: Scott Thompson <email@hidden>
  • Date: Fri, 17 Jul 2009 00:55:35 -0500


On Jul 16, 2009, at 7:24 AM, Wilson Chen wrote:

Hi all,

I'm new to the Cocoa framework, and puzzled why the following code would
work:


CGLayerRef layer = ...assume we have a layer created.
printf("Retain count after creation: %i\n", CFGetRetainCount(layer));

[(NSObject*)layer retain];
printf("Retain count after sending a retain message: %i\n",
CFGetRetainCount(layer));

[(NSObject*)layer release];
printf("Retain count after sending a release message: %i\n",
CFGetRetainCount(layer));

The code above gives the following output:

Retain count after creation: 1
Retain count after sending a retain message: 2
Retain count after sending a release message: 1

Since a CGLayer is not a subclass of NSObject, its instances shouldn't
respond to retain/release messages. Yet the code works.

This code works in a non-garbage collected environment. In a garbage collected environment, the Objective-C retain and release calls would be ignored while CFRetain and CFRelease would not. Your best bet is to not mix the two paradigms.




_______________________________________________

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: 
 >Why do CFType instances respond to NSObject messages? (From: Wilson Chen <email@hidden>)

  • Prev by Date: Activating and deactivating core layer animation
  • Next by Date: Re: [iPhone] Custom -sizeWithFont: and CGContextRef question
  • Previous by thread: Re: Why do CFType instances respond to NSObject messages?
  • Next by thread: Why do CFType instances respond to NSObject messages?
  • Index(es):
    • Date
    • Thread