Releasing a loaded script from memory
Releasing a loaded script from memory
- Subject: Releasing a loaded script from memory
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 28 Mar 2003 12:12:13 -0800
I know we usually don't have to bother setting variables to null or Nothing
in AppleScript, like they do in other languages. They get cleaned up when
the script ends. But I think I've found a case where it's essential, Can it
be done, and if so, what's the best way - just 'null' or 'missing value'?
The variable in this case is a loaded script. Here's the situation:
Some of you may recall the really terrible bug I discovered a few months ago
that I call the "Lost Script" bug. This was where one script (A) loaded
another (B), changed some properties and tried to store B replacing yes, and
then when quitting couldn't save itself (A) to its own applet shell and
instead got replaced by the (updated) script B! B itself never got updated.
I found that I could replicate this 100% when script A contained 'store
script', a quit handler, and a call to the Finder in the quit handler.
Removing the call to the Finder made it much less than 100% replicable, but
it still occurred sometimes as long as 'store script' and a quit handler
were in the same script (A).
So I completely re-did the script and removed 'store script' from A (it
really needs that quit handler). Instead this is my technique now:
When script A needs to be updated, I post a new version (A.0.1). I tell
users to run script B in a mode that loads script A, gets the value of a few
properties there, then loads A.0.1 and sets the same properties in A.0.1 to
the obtained values from A, and stores A.0.1 replacing yes.
For 95% of users this works fine. But gradually more users are hitting the
"Lost Script" bug again: script B is saved into A.0.1's shell, B gives the
error that it can't set the properties, and if they try to run A.0.1 it
turns out be script B. On the other hand, if they update in a lengthier
mode I also provide, whereby they don't load script A at all, just A.0.1,
and enter an "educated guess" for the important property, A.0.1 gets stored
and saved just fine.
A critical issue is that A and A.0.1 are very large scripts: 138K each as
text source, with lots of properties and handlers. I believe that loading
two huge scripts is proving too much for script B's memory, and that's
what's creating the problem when it comes to store one of them (A.0.1).
I want to test out setting the variable oldScript here:
set oldScript to load script "A"
to null or to missing value after getting the necessary property values from
it, before loading script "A.0.1". Will this work, or is there a better way
to do it?
--
Paul Berkowitz
_______________________________________________
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.