Sheets, blocks and garbage collector
Sheets, blocks and garbage collector
- Subject: Sheets, blocks and garbage collector
- From: Frédéric Testuz <email@hidden>
- Date: Sat, 6 Feb 2010 16:31:58 +0100
Hi all,
I'm beginning a new application targeting Snow Leopard only. So I want to use the new tools (blocks) and garbage collection (GC). It will be my first application using GC.
I read some sites on GC and blocks. In the blog of Mike Ash I found some very interesting propositions. My question concerns his code for using block with sheets (http://www.mikeash.com/?page=pyblog/friday-qa-2009-08-14-practical-blocks.html). Is this code works in GC ?
@implementation NSApplication (SheetAdditions)
- (void)beginSheet: (NSWindow *)sheet modalForWindow:(NSWindow *)docWindow didEndBlock: (void (^)(NSInteger returnCode))block
{
[self beginSheet: sheet
modalForWindow: docWindow
modalDelegate: self
didEndSelector: @selector(my_blockSheetDidEnd:returnCode:contextInfo:)
contextInfo: [block copy]];
}
- (void)my_blockSheetDidEnd: (NSWindow *)sheet returnCode: (NSInteger)returnCode contextInfo: (void *)contextInfo
{
void (^block)(NSInteger returnCode) = contextInfo;
block(returnCode);
[block release];
}
@end
I think, I have to replace [block copy] by CFRetain([block copy])
and [block release] by CFRelease(block).
Frédéric
_______________________________________________
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