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 protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]