Re: what is the best way to 'unset' a variable
Re: what is the best way to 'unset' a variable
- Subject: Re: what is the best way to 'unset' a variable
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 23 Mar 2002 11:01:05 -0800
On 3/23/02 10:05 AM, "Christopher Nebel" <email@hidden> wrote:
>
Being a garbage-collected language, AppleScript
>
will hold on to any value that someone (such as a variable) has a
>
reference to. If no one has a reference, then the value is garbage, and
>
its memory can be reclaimed. Therefore, setting a variable to something
>
small will allow the collector to reclaim memory earlier than it
>
otherwise would. The same trick is commonly used in Java: you don't
>
delete objects, you just make sure no one knows about them any more.
Thanks, Chris. What about script objects, as the original questioner asked?
Should they be evaporated too? And in OS X, will much advantage be gained
from releasing memory with just a few lines of script to go?
>
>
This isn't a big issue for local variables, because they get destroyed
>
automatically when they go out of scope, but it is an issue for
>
properties and globals, and if you write your script without using
>
handlers, all your variables are global.
When I'm still developing a script, I find it rather handy to have those
values retained if something goes wrong while the script is running in its
native habitat (as an applet, or as a compiled script running from another
app). I can actually debug by opening the script in Script Debugger and
finding the current values of all variables just waiting there for me. I had
noticed script size and wondered whether this was "extra SD stuff", but I
guess a lot of it is just retained variable space. I like it, and can afford
the disk space, thanks, but it's good to know what's happening. Thanks.
>
>
As J. Baxter pointed out, it can pay to clear out globals and properties
>
you don't need when the script finishes, because their values get stored
>
back into the script. Normally, that's a feature, but if you don't care
>
about the value, then it's wasted disk space.
But not usually a major issue, really.
--
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.