• 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: Intercepting retain/release of object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Intercepting retain/release of object


  • Subject: Re: Intercepting retain/release of object
  • From: Pierre Molinaro <email@hidden>
  • Date: Wed, 19 Mar 2008 19:09:18 +0100

The retain method should return self object :

- (id) retain
{
	unsigned int count = [self retainCount] + 1;
	NSLog(@"RETAIN: retain count after retain is: %i", count);
	return [super retain] ;
}

After calling [super release], the current object may not exist any more; try:

- (void) release
{
	unsigned int count = [self retainCount] - 1;
	NSLog(@"RELEASE: retain count after release is: %i", count);
	[super release];
}

- Pierre

Le 19 mars 08 à 18:54, Stuart Malin a écrit :

I am having some trouble in an app with an object and its retain counts, so I added methods to intercept -retain and -release on my affected object so I could set breakpoints to observe the value. But doing so causes some really odd behavior, such as the object receiving extra retain events (such as when it is _removed_ from an array). Why would my intercepting these, but nonetheless propagating them up the class hierarchy, cause problems?

- (void) retain
{
	[super retain];
	unsigned int count = [self retainCount];
	NSLog(@"RETAIN: retain count after retain is: %i", count);
}

- (void) release
{
	[super release];
	unsigned int count = [self retainCount];
	NSLog(@"RELEASE: retain count after release is: %i", count);
}

_______________________________________________

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: 
 >Intercepting retain/release of object (From: Stuart Malin <email@hidden>)

  • Prev by Date: Re: Intercepting retain/release of object
  • Next by Date: Re: Intercepting retain/release of object
  • Previous by thread: Re: Intercepting retain/release of object
  • Next by thread: Re: Intercepting retain/release of object
  • Index(es):
    • Date
    • Thread