我有个奇怪的数据泄露,希望有人能解释这里出了什么问题。最小的工作示例项目如下:
Info.plist和main.m以外的所有内容Info.plist do中:Main nib file base name。Principal class更改为"AppHook“。LSUIElement并将其设置为YES。
接下来,将main.m更改为:
#import <Cocoa/Cocoa.h>
#import "AppHook.h"
int main(int argc, const char * argv[]) {
[[AppHook sharedApplication] run];
return 0;
}并添加以下两个新文件:AppHook.h
#import <Cocoa/Coco a.h>
@interface AppHook : NSApplication <NSApplicationDelegate, NSMenuDelegate>
@property (strong) NSStatusItem *barItem;
@end和AppHook.m
#import "AppHook.h"
@implementation AppHook
- (instancetype)init {
self = [super init];
self.delegate = self;
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.barItem = [NSStatusBar.systemStatusBar statusItemWithLength:NSVariableStatusItemLength];
self.barItem.highlightMode = YES;
self.barItem.title = @"yep";
self.barItem.menu = [[NSMenu alloc] initWithTitle:@"M"];
self.barItem.menu.delegate = self;
self.barItem.menu.autoenablesItems = NO;
}
- (NSInteger)numberOfItemsInMenu:(NSMenu*)menu {
return 1;
}
- (BOOL)menu:(NSMenu*)menu updateItem:(NSMenuItem*)item atIndex:(NSInteger)index shouldCancel:(BOOL)shouldCancel {
item.title = [NSString stringWithFormat:@"%@", [NSDate date]];
return YES;
}
@end当使用仪器和泄漏模板运行此应用程序时,我得到以下CFData泄漏:
0 Malloc +1 1 00:03.319.300 AppKit _DPSNextEvent
1 CFRetain +1 2 00:03.319.303 AppKit CopyCarbonUIElementAttributeValue
2 CFRelease -1 1 00:03.319.310 AppKit _DPSNextEvent每次打开和关闭状态菜单时,都会发生这种情况。所以反复点击菜单图标会产生大量的漏洞。
这里没有什么特别之处,只是NSApplication的一个子类(我需要重写sendEvent(_:))。
发布于 2018-12-02 01:20:47
所以..。经过相当长的一段时间后,这种情况又发生了。
简短答覆:
重启你的Mac。
较长的答覆:
正如你所看到的,我最近的评论是近一个月前。从那时起,我重新启动了我的mac两次,并始终检查Xcode探查器之前。对于这两个重新启动,Profiler没有显示任何泄漏。我不知道上次重启是什么时候,大约两周前。今天我注意到Profiler又显示了同样的泄密。
不是起作用的是什么?
似乎是macOS本身的一个bug。我会创建一个bugreport,但老实说,我甚至不知道该写什么。繁殖力是偶然的:
而且,它不依赖于特定的项目。使用此示例项目作为参考,并保持它在上个月没有任何变化。
https://stackoverflow.com/questions/53182641
复制相似问题