Home (Spotlight) | TOC
| Products & Ordering | Technical
Info | Contact Zeus
Zeus Tech Note
Memory Leaks
(This document last revised July 8, 1997)
Copyright © 1996-1997. Zeus
Productions. All Rights Reserved.
Written by Bruce A. Epstein
Q. What is a memory leak?
A. A memory leak occurs when a program, DLL, Xtra or XObject allocates memory
without releasing it at a later time. The system thinks that the memory
is in use, but it is not deallocated properly. This causes the allocated
RAM to be lost from the pool of available RAM. Even if a memory leak is
small (a few dozen bytes), the cumulative affect over thousands of iterations
can lead to a crash if Director runs out of memory.
Q. How do I detect a memory leak?
A. You can used the Lingo "the freebytes
" to display
the amount of memory available to Director. Under Windows, this amount will
fluctuate as the OS allocates memory dynamically to Director. It will also
change depending on what Director has loaded into RAM. You can use the "unload"
command to clear castmembers from RAM.
You can test your program for leaks by repeatedly performing the operation
you suspect of causing the leak, and checking "the freebytes"
periodically. For example, to test if a command causes a leak, you might
use:
repeat with x = 1 to 100
-- Test it here
someCommand()
put "The freeBytes equals" && the freeBytes.
end repeat
Q. What causes memory leaks?
There are several factors to consider:
- Director does its own memory management, and there is a tendency for
it to consume memory slowly and then periodically free it up in one big
chunk. Therefore, the available memory should decline steadily and then
periodically increase again. This is not an actual memory leak, and is expected
as Director loads and unloads assets from the Cast. It is possible that
certain features of Director would contain bugs that would cause a memory
leak. These leaks may not occur with your use of Director, or may not exist
at all, depending on the version of Director in use.
- The message window itself consumes memory steadily and then periodically
releases it. If you create a repeat a loop that simply prints out the freebytes,
you will see that the available memory decreases. This is not an actual
memory leak.
- While Lingo code itself cannot create a memory leak, it is possible
to use Lingo to call Xtras which may leak memory. Even if an Xtra does not
leak, Director will manage the memory used by Lingo for Xtras, and then
periodically release it when the Xtra or instance is no longer in use.
You should instantiate an Xtra, using the "new" method, only
once. A common error is to instantiate it repeatedly, once each time it
is used. This would consume memory, especially if you do not free the object
each time by setting its value to zero. Even if you free the object, there
is a delay in Director reclaiming the memory, so it is best to instantiate
the object once outside the loop.
- If instantiating an XObject (with mNew) failure to use the mDispose
method (to dispose of the instance when you are done with it) will cause
memory to leak. If using an Xtra, you do not use the mDispose or
"forget" method. Simply set the instance variable equal to zero
when you are done with it, and Director will reclaim the memory at a later
time.
- Director, an Xtra, an XObject or an external application may be leaking
memory, but it may be beyond your control to prevent it. Report the bug
to the manufacturer and try to obtain the latest version of the software
which may address the issue.
Home (Spotlight) | Table
of Contents | Links | Contact
Info
Place an Order | Products
for Sale | Licensing | Downloads
TechNotes | FAQs
| E-Mail Zeus | GuestBook
| Glossary
Copyright © 1996-1997. Zeus
Productions. All Rights Reserved.