• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: what is the best way to 'unset' a variable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: what is the best way to 'unset' a variable


  • Subject: Re: what is the best way to 'unset' a variable
  • From: Christopher Nebel <email@hidden>
  • Date: Sat, 23 Mar 2002 10:05:12 -0800

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.


--Chris Nebel
AppleScript Engineering
_______________________________________________
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.

  • Follow-Ups:
    • Re: what is the best way to 'unset' a variable
      • From: email@hidden (Michael Sullivan)
    • Re: what is the best way to 'unset' a variable
      • From: Paul Berkowitz <email@hidden>
References: 
 >Re: what is the best way to 'unset' a variable (From: Paul Berkowitz <email@hidden>)

  • Prev by Date: Re: Finding folder from its id
  • Next by Date: Another Finder Bug or two
  • Previous by thread: Re: what is the best way to 'unset' a variable
  • Next by thread: Re: what is the best way to 'unset' a variable
  • Index(es):
    • Date
    • Thread