对于NSAppleEventDescriptor巨大的内存泄漏,obj-c

时间:2016-03-20 00:26:49

标签: objective-c memory-management automatic-ref-counting

    NSDictionary *error = nil;

//AppleScript to get all running windows
NSAppleScript *appleScriptFindWindows = [[NSAppleScript alloc] initWithSource:
                         @"tell application \"System Events\" to get the title of every window of process \"TestWindow\" whose name contains \"Black\" end tell"];


while (true) {
    @autoreleasepool {
        //Execute and get the result of the OSAScript
        NSAppleEventDescriptor *result = [appleScriptFindWindows executeAndReturnError:&error];

        //Convert the result to a string
        NSString *windowNames = [NSString stringWithFormat:@"%@", result];

        error = nil;

        sleep(0.25);
    }

}

我知道我目前没有做任何结果,但是一旦我解决了问题,我就会做。

我将在连续循环中使用applescript监视各种窗口/文件,但是我注意到当我运行此代码时,我的内存使用率突然增加到12mb / s并且能量影响很大。由于arc,我无法释放或取消分配AppleEventDescriptor。

有没有办法释放事件描述符,或者我错过了AppleScript中的某些内容,以便在执行后正确退出?

我在这一点上有点迷失并且是obj-c的新手我想知道是否有更好的方法在obj-c中执行applescript,如果这是问题。

0 个答案:

没有答案