@autoreleasepool in AppleScriptObjc with ARC

292 views Asked by At

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?

1

There are 1 answers

0
Chris Paveglio On BEST ANSWER

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.