• 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: ivar access during -finalize
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ivar access during -finalize


  • Subject: Re: ivar access during -finalize
  • From: "email@hidden" <email@hidden>
  • Date: Sun, 11 Mar 2012 01:08:30 +0000

On 10 Mar 2012, at 22:51, Eric Wing wrote:

> Just another angle on your original problem, have you considered using
> CFRetain and CFRelease on _myIvar? These are still meaningful in
> garbage collection mode. Using CFRetain when you get/create _myIvar,
> it would presumably still be alive in your finalize method until you
> call CFRelease on it.
>
That sounds like an inspired piece of thinking!

I will try something like the following:

- (id)init
{
	self = [super init];
	if (self) {
		// assign ivar
		_myIvar = @"~/workfile";
		[[NSFileManager defaultManager] createFileAtPath: _myIvar contents:nil attributes:nil];
		CFRetain(_myIvar);
	}
	return self;
}

- (void)finalize
{
	// _myIvar is still retained so it should not yet be finalised
	[[NSFileManager defaultManager] removeItemAtPath: _myIvar error:nil];

	// now release the ivar
	CFRelease(_myIvar);
}

The garbage collection programming guide says:

You should typically use NSMakeCollectable() on Core Foundation objects rather than relying on CFRelease() in finalize—this way collectable Core Foundation objects are actually collected sooner. (Collectable objects are collected with the source object whereas released objects are simply marked as being eligible for collection—these must wait for the next collection cycle to be collected.)

To me the above implies that calling CFRelease in finalise is doable.

Regards

Jonathan Mitchell
Mugginsoft LLP
_______________________________________________

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


  • Follow-Ups:
    • Re: ivar access during -finalize
      • From: Quincey Morris <email@hidden>
References: 
 >ivar access during -finalize (From: "email@hidden" <email@hidden>)
 >Re: ivar access during -finalize (From: Quincey Morris <email@hidden>)
 >Re: ivar access during -finalize (From: "email@hidden" <email@hidden>)
 >Re: ivar access during -finalize (From: "email@hidden" <email@hidden>)
 >Re: ivar access during -finalize (From: Eric Wing <email@hidden>)

  • Prev by Date: Re: ivar access during -finalize
  • Next by Date: Re: ivar access during -finalize
  • Previous by thread: Re: ivar access during -finalize
  • Next by thread: Re: ivar access during -finalize
  • Index(es):
    • Date
    • Thread