0
我的應用程序在GC打開的情況下運行。Objective-c中的ShowModalWindow會導致GC上的內存泄漏?
儀器泄漏總是告訴我,這行代碼具有100%的內存泄漏:
[NSApp表示runModalForWindow:[theWindowController窗口]];
我不知道爲什麼...
這裏是整個應用程序的代碼:
/* delegate */
#import "m_ModalWindowAppDelegate.h"
#import "modalWindowController.h"
@implementation m_ModalWindowAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
- (IBAction) openModalWindowButtonClicked: (id) sender
{
modalWindowController *theWindowController = [[modalWindowController alloc] init];
[NSApp runModalForWindow:[theWindowController window]];
[NSApp endSheet: [theWindowController window]];
[[theWindowController window] orderOut:self];
}
@end
/* modalWindowController */
#import "modalWindowController.h"
@implementation modalWindowController
- (id) init
{
self = [self initWithWindowNibName:@"modalWindow"];
return self;
}
- (IBAction) closeButtonClicked:(id)sender
{
[NSApp stopModal];
}
@end
感謝您的回覆。應用程序項目已開啓Garbage Collection,因此WindowController將由垃圾收集收集?這就是我從GC手冊中讀到的內容,當GC開啓時,autorelease將無用。 – 2011-03-18 17:19:17