von dp am 28.Januar 97 um 16:15:41:
zu: Subject: Deleting an object - style guide von dp am 18.Januar 97 um 01:53:51:
The continuing saga of nulling out an object reference...
On 1/17/97, julian baker wrote (in part):
> what's wrong with
> set gMyGroovyObject = void
Unless you have a variable named "void" (and I hope you don't), this won't
work inside a script. Lingo doesn't know "void", so it assumes it's the
name of a local variable. When I try this line inside a script, I get
"variable used before assigned a value".
Incidentally, it *will* work in the message window, where unknown
identifiers are assumed to be global variables initialized to void. (For
the same reason, set gMyGroovyObject = FunkyGroovyLingoHacker will probably
work just as well in the message window.)
(VOID is one of those constants we keep meaning to add to Lingo. It'll
probably show up in a future release.)
On 1/15/97, Michael Scaramozzino wrote (in part):
> > set gMyGroovyObject = value(void)
> Is this any better than simply setting it to 0
Not particularly. As W. Dana Nuon pointed out, 0 won't work if you're using
voidP to find uninitialized objects. Also, the showGlobals command
suppresses display of globals whose value is void. It's really just a
personal preference, though.
Michael Scaramozzino also asks for...
> Any technical details about how Lingo handles internal variables
Here goes...
> Does this [the value(void)]
> approach actually release more memory? The memory used for the variable
> itself? Does setting it to void release it from the symbol table or
> something similar?
Nope. The integer 0 and the value void both take up the same amount of memory.
The amount of memory a value uses depends on the type of the value:
- Simple types (integer, void, symbol) all take up the same, fixed amount
of memory (currently 8 bytes, the same as a MoaMmValue).
- Complex types (string, list, object, etc.) take up the same fixed memory
as the simple types, plus additional memory to hold the variable length
data.
Lingo values always carry their types around with them. When a value is
assigned into a variable, its type is assigned along with it. The type of
value previously in the variable has no effect on the new type of the
variable. (There's no automatic casting or anything like that.) If the
previous value was a complex type, the additional memory it was using is
released when all the references to it are gone.
While a variable is alive, there's always a slot allocated to store its
value. That slot is exactly the size needed for a simple value. One
implication of this is that there is nothing you can assign into a variable
to free the memory used by its slot, because even the void value takes up
the standard slot size.
There are three possible variable lifetimes in Lingo:
- Local variables (those used only in a particular handler) are in scope
only while the handler they are in is executing. Their slots are freed when
the handler returns.
- Properties are stored along with their object instances. There slots are
freed when the object is destroyed (which is when all references to it are
gone).
- Global variables live forever (or at least, until you quit Director).
clearGlobals will void out the values, but the slots themselves are not
freed.
Remember that a variable slot is just eight bytes. Even a whole movie's
worth of global *slots* is unlikely to come anywhere near the memory used
by the movie's bitmaps. Trying to optimize by freeing up slots is unlikely
to have a big payoff. Complex values can take up a lot of memory, though,
so it's reasonable to optimize by voiding out global references to large
strings or lists when you're done with them.
Hope this helps.
- Mike Edmunds
Macromedia Director Engineering
medmunds@macromedia.com
D. Plänitz