Hey guys. I don’t really have any solutions to present, but I thought I would jump in and add my 2 cents to this discussion.
I’m not sure that this is necessarily a problem with your code, but perhaps in the combination in which you’re doing certain things… and also in problems which may be inherent in ASStudio itself. I think that ASS is fundamentally limited in it’s ability to do certain things which are very memory intensive. I, and I assume many others, regularly make assumptions about it’s abilities and do not take into consideration it’s limitations. Memory management is one of the most talked-about goblins in efficient cocoa programming. Because of it’s relationship with cocoa, applescript studio ultimately must live with this burden as well. Although you’ve tried the delete command to try to manually ‘release’ the images, I agree with ktam, that this may not be doing everything you need it to. I’m no expert on memory, but I could see that a weak implementation of the delete command or a bug in ASS’s automatic memory deallocation may not be releasing all of the memory you try to allocate. Perhaps it is deleting it’s connection to the memory, but not actually freeing the memory from disk?
I searched around a bit and found that malloc errors are generally common for people trying to load large amounts of data… not just in image form, either. I even found one post where some guys were forcing the OS to incrementally load increasingly large files to find the memory allocation limit… which eventually lead the whole machine to crash. :shock:
I’m guessing that one or two things are happening. You could be slowly adding memory to shared memory until you reach your available limit… and/or you’ve found a limitation of applescript studio. Have you been able to determine a finite limit to the memory you are able to load? Obviously there’s not much we can do to help without a copy to test ourselves, and like ktam, I don’t have much more input to give. I would try a scientific approach, such as doing some baseline tests on the cause of the problem. I’d try restarting the machine, launching your app, and doing some structured tests. Try loading the same file(or files) in the same order in generally the same conditions (time, frequency,interval, etc.). Do this a few times to see if starting from scratch leads to some regular results. Perhaps if you could establish some patterns, by adding up the time taken or total size of the combined files, you might see that there actually was one problem that could be reproduced… and ultimately solved.
I assume you are using some sort of memory monitor to watch as you test the app, to see what is happening at the exact moment the error occurs. Sometimes seeing the memory spike at a certain moment can lead to a more precise evaluation of the cause. Also, is the error occurring when you reference the item from the data source, or when you try to load the image using the path found in the data source? Just to clarify, you said “The images are stored in a data source.”, but you mean that a list of paths to those images is stored in the data source, right? Can’t imagine how you’d do it otherwise, but I had to ask… a few works can make all the difference, no? 
Good luck, and let us know what you find…
j