Re: Memory usage in AppleScript... How to prevent out of memory errors?
Re: Memory usage in AppleScript... How to prevent out of memory errors?
- Subject: Re: Memory usage in AppleScript... How to prevent out of memory errors?
- From: Arthur J Knapp <email@hidden>
- Date: Sun, 17 Jun 2001 15:50:03 -0400
>
Date: Sun, 17 Jun 2001 09:50:14 +0100
>
Subject: Memory usage in AppleScript... How to prevent out of memory
>
errors?
>
From: Simon Forster <email@hidden>
>
I have a relatively simple script which downloads a bunch of data, deletes
>
any returns in the data ...
Are you using the text item delimiters to delete the returns? There is
an upper limit of approximately 4060 some items that AppleScript will
return as the result of a string-to-string-elements coercion:
-- BigString = a string with 5000 return characters
set text item delimiters to {return}
set SomeRecords to text items of BigString --> error
>
... and concatenates it into one large file. ...
Are you reading this large file into memory? If so, you don't have to:
set forAppend to open for access alias "path:to:data file"
write (theString) starting at (get eof forAppend) to (forAppend)
>
... The script
>
works fine for small quantities of data (314 records, 195,131 bytes) but
>
consistently returns "Error -108. Not enough memory to complete this
>
operation" when run with larger data sets (just shy of 2,500 records). I
>
have thrown silly amounts of memory at the script application but this
>
doesn't help.
Which would lead one to suspect a hard-coded limit of some kind...
>
Also, the script application has quite a large memory footprint after
>
running - 516 K having run against the 314 records data set. The only
>
properties are for cr, lf, crlf and the folder path to the script
>
application. So why such a large file after running? Would the script be
>
remembering the data set? If so, why? It's NOT a property.
Actually, I seem to remember someone posting something about top-level
variables retaining their value after a script has run. (Does anyone
know anything about this?)
If you suspect that this is the case, the solution is simply to move
everything inside of a handler. Variables declared within a handler are
cleared when the handler has finished execution:
main() -- The only top-level statement in your script
on main()
-- do everything here
end main
>
Anyway, it seems that the script is failing when it comes to write the
>
finished product out to disk. I'll keep on checking it but would appreciate
>
any pointers on what could be causing problems here.
Perhaps if you could post just a small snippit of the section where the
"write" operation is performed?
Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden
Hey, check out:
http://www.AppleScriptSourceBook.com