Python에서 몇 년을 보낸 후에 Objective-C로 시작합니다. 몇 가지 개념으로 머리를 감싸기 위해 노력하고 있습니다.이 점을 알 수는 없지만 늘릴 때마다 늘리거나 공제합니다. myCount
메모리에있는 오래된 변수. 나는 ARC를 사용하고있어서 autorelease하지 않아야합니까? 나는 그것이 self.varOfMyCount = [NSString stringWithFormat:@"%d", myCount];
Objective-C에서 가능한 메모리 누수가 있습니까?
헤더과 관련이있다 느낌이있다 :
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
IBOutlet NSMenu *statusMenu;
NSStatusItem *statusItem;
}
- (IBAction)itemOne:(id)sender;
- (IBAction)itemTwo:(id)sender;
- (IBAction)itemThree:(id)sender;
@property (assign) IBOutlet NSWindow *window;
@property (nonatomic, copy) NSString *varOfMyCount;
@end
int myCount = 0;
: 구현에 문제가있는 것처럼
#import "AppDelegate.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength ];
[statusItem setMenu:statusMenu];
[statusItem setTitle:@"Status"];
[statusItem setHighlightMode:YES];
}
- (IBAction)itemOne:(id)sender {
myCount++;
self.varOfMyCount = [NSString stringWithFormat:@"%d", myCount];
NSLog(@"%@",self.varOfMyCount);
[statusItem setTitle:self.varOfMyCount];
}
- (IBAction)itemTwo:(id)sender {
myCount = myCount-1;
self.varOfMyCount = [NSString stringWithFormat:@"%d", myCount];
NSLog(@"%@",self.varOfMyCount);
[statusItem setTitle:self.varOfMyCount];
}
- (IBAction)itemThree:(id)sender {
NSLog(@"Quit.");
[[NSApplication sharedApplication] terminate:nil];
}
@end
이러한 인스턴스가 해제되지 않았다고 어떻게 결정 했습니까? – Wain
액티비티 모니터에서 나는 더 많은 메모리를 먹고있었습니다. – Matthew
악기를 사용하여 정확한 할당 (및 누출)을 확인 했습니까? – Wain