【发布时间】:2011-03-18 15:25:30
【问题描述】:
我的应用在 GC 开启的情况下运行。
Instrument Leak 总是告诉我这行代码有 100% 的内存泄漏:
[NSApp runModalForWindow:[theWindowController window]];
我不知道为什么。
这是整个应用程序代码:
/* 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
【问题讨论】:
标签: objective-c memory-leaks garbage-collection