Re: Garbage collection and objects
Re: Garbage collection and objects
- Subject: Re: Garbage collection and objects
- From: email@hidden
- Date: Mon, 12 Feb 2001 22:23:11 -0500
On Date: Mon, 12 Feb 2001 17:09:47 -0500, Victor Yee <email@hidden>
asked,
>
I hope I'm using the correct terminology:
>
>
Do objects persist after their pointers are assigned to another object?
>
>
set x to makeObject(1)
>
set x to makeObject(2)
>
>
Does the first result of makeObject() get sent to garbage collection?
AppleScript does garbage collection when it need more memory. Like other
languages that can share data between two variables, it can't just deallocate an
object when one reference to it disappears, but must garbage collect based on
what object are still reachable. But its behavior is a little different than
most applications you might be familiar with. When it decides to do a garbage
collection run, it walks through every variable that is in use, and duplicates
it to new memory. It then clears out the old memory in toto.
This garbage collection is needed not just for reassignment as shown in your
example, but for every intermediate result that involves a list, or record. So,
set myOptions to myOptions & "Take a nap"
the previous value of myOptions is cast adrift, and becomes eligible for garbage
collection (assuming there is no other list variable sharing the value).
Avoiding this garbage generation is a good reason for using
set end of myOptions to "Take a nap"
in preference to the concatenation.
>
Or to put it another way, can this lead to a memory leak?
If you watch memory use, you'll think you have a leak, as memory in use grows
and grows. Then the garbage collector kicks in, and the objects in use bop over
to new memory, and the old hunk clears out.
But...... There was a problem with this process in some version of Applescript,
which dropped a byte or two in the symbol table when doing the copying to new
memory. So you'd have a very slow leak.
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden