AppleScriptObjC 中的 NSImage release()

NSImage release() in AppleScriptObjC

我正在创建一个 Table 视图,每行显示小图像。 data source 为 table 的每一行保存一个图像。我通过 set img to NSImage()'s alloc()'s initWithContentsOfFile_(thePath) 创建图像。接下来,我通过 set imageView's image to img 在更大的浏览器视图中显示所选行的图像。问题是我 运行 内存不足,因为我对两个视图使用相同的表示。 (图像约为 500x400)。 我想弄清楚如何从较大的版本制作较小的版本,然后发布更大的图像。

我从发布图片开始.. 我试过 img's release() 但没用。除了 Garbage Collection, ARC, and managing memory 之外,我找不到关于该主题的任何信息。我在 XCode 中启用了 Objective-C Automatic Reference Counting 但它可能不适用于交易的 Applescript 部分。有没有办法在纯 ApplescriptObjC 中实现它?

试试这个代码(根据您的变量名和 UI 控件属性进行调整):

set curImage to current application's NSImage's alloc()'s initWithContentsOfFile:thePath

-- create a smaller image

set newImage to current application's NSImage's alloc()'s initWithSize:{48, 48}

newImage's lockFocus()

curImage's drawInRect:{{0,0}, {48, 48}} fromRect:{{0,0},{0,0}} operation:2 fraction:1.0

newImage's unlockFocus()

imgArtwork's setImage:newImage 

set curImage to missing value -- release large image