문제

I want to make an autoreleasepool in AppleScriptObjc with ARC, but I couldn't retain it. Here's the code:

property NSAutoreleasePool : class "NSAutoreleasePool"
script AppDelegate
    ...
    on buttonClicked_(sender)
        set pool to NSAutoreleasePool's alloc()'s init()
        ...
        pool's drain()
    end buttonClicked_
end script

In the code, I got this debug error:

-[NSAutoreleasePool retain]: Cannot retain an autorelease pool (error -10000)

I googled and I found that "[[NSAutoreleasepool alloc] init]" can be used only without ARC, instead, "@autoreleasepool" can be used with ARC and without ARC.

In Objective-C, we can use @autoreleasepool. Example:

int main()
{
    @autoreleasepool {
        ...
    }
}

But AppleScriptObjc doesn't have '{' or '}', so we can't use @autoreleasepool. However, I tried it, and I got an error.
Code:

@autoreleasepool
    ...

Error:

error: Expected “end” but found unknown token. (-2741)

How can I use @autoreleasepool in AppleScriptObjc?

도움이 되었습니까?

해결책

Autoreleasepool is out of your control- you can't do it in ASOC. Memory management is handled by the framework. Why exactly do you think you need autoreleasepool? Applescript is single threaded, and you'd have to use Objective-C code if you want to try to kick off another threaded process, but it can't be an Applescript/ASOC process, only pure Obj-C.

See this post for additional discussion about it: http://macscripter.net/viewtopic.php?id=41359 Shane Stanley is very knowledgeable on ASOC, read his posts.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top