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: email@hidden (Michael Sullivan)
- Date: Mon, 25 Mar 2002 15:36:26 -0500
- Organization: Society for the Incurably Pompous
>
On Friday, March 22, 2002, at 07:16 PM, Paul Berkowitz wrote:
>
> If x is not a script property (properties persist over script runs),
>
> there's
>
> no benefit to "unsetting" x at all, unlike for example setting
>
> variables to
>
> Nothing in VBA. It doesn't unset them nor free up any memory: it's just
>
> another operation.
>
That's not really true. 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.
>
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.
>
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.
What's the reasoning behind storing globals in the script when it's
finished? They go away as soon as it runs again anyway? I've always
assumed that if I wanted a variable value to persist, it needed to be in
a property.
Can other scripts still call for the global's value after it is finished
running, and it won't be lost until the script is actually run again?
Michael
--
Michael Sullivan
Business Card Express of CT Thermographers to the Trade
Cheshire, CT email@hidden
_______________________________________________
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.