recursion testing (was: Finder - Delete empty folders, recursively)
recursion testing (was: Finder - Delete empty folders, recursively)
- Subject: recursion testing (was: Finder - Delete empty folders, recursively)
- From: Graff <email@hidden>
- Date: Mon, 14 Jun 2004 23:24:40 -0400
Ok, I was bored... :-)
I decided to make a simple recursion test to see how many instances of
a handler could be opened. I came up with 284. I'm running a PowerMac
G5 dual 2 gHz, 1.5 GB RAM, Mac OS 10.3.4 with all updates, AppleScript
1.9.3, and Script Editor 2.0 (v43). Here's the script I used:
----
global totalRecurse
on recurse()
set totalRecurse to totalRecurse + 1
try
recurse()
on error
display dialog "failed at: " & totalRecurse
end try
end recurse
set totalRecurse to 0
recurse()
----
After a fraction of a second I get a dialog that says "failed at: 284"
This tells me that the deepest you can dig into a folder hierarchy
using a recursive algorithm is about 284 levels deep. I don't think
I've even had to dig that deep but I've definitely had recursive
algorithms fail on me so there may be some other limiting factor to
calling so many instances of handlers.
Adding this line to the recurse handler caused a failure at 265:
set variable1 to 1
Additional variables caused the amount to keep falling:
2 248
3 234
4 221
5 209
6 199
7 189
8 181
9 173
And so on. Saving the script as an application and running it made no
difference. The size and type of the additional variables didn't seem
to make a difference, although I wasn't too thorough in testing that.
Anyone else get anything different?
- Ken
On Jun 14, 2004, at 8:56 PM, Graff wrote:
And just to comment on why I said that recursion can be a problem with
AppleScript. This is due to the fact that the large number of handler
instances created by recursion can overflow AppleScript's ability to
open new handler instances. I'm not sure of the limits but I have
definitely seen it happen. If it is at all possible use a list
instead of recursion. With AppleScript a list can handle far more
elements than recursion can, in most instances. In this current
example the recursion is very useful because it enables you to check
the folders as the recursion unwinds, that's why I stuck with it even
if it might fail in some circumstances.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.