TI-994A wrote:1. Add it to the auto-release pool (which might be the default behavior)
2. Release it manually
3. Destroy the image
1. The image object created with
iconForFileType is already added to the autorelease pool by the OS itself so you are not supposed to add "autorelease" yourself.
2. Autorelease objects should not be released with "release" as it will cause a crash if the OS already drained or released the autorelease pool.
3. This is the equivalent of method 2 so also not allowed in this case.
What you should do is nothing and let the OS release the object if you are using it within the main event loop.
If you are using the method in a place where there's no autorelease pool, create a pool yourself like this.
Code: Select all
Pool = CocoaMessage(0, 0, "NSAutoreleasePool new")
ImageID = CocoaMessage(0, CocoaMessage(0, 0, "NSWorkspace sharedWorkspace"), "iconForFileType:$", @"txt")
CocoaMessage(0, Pool, "release")
Inside a loop it also may be good to create a pool yourself.
Code: Select all
Workspace = CocoaMessage(0, 0, "NSWorkspace sharedWorkspace")
For i = 1 To 100000
Pool = CocoaMessage(0, 0, "NSAutoreleasePool new")
ImageID = CocoaMessage(0, Workspace, "iconForFileType:$", @"txt")
CocoaMessage(0, Pool, "release")
Next