Shaoping Zhou <[EMAIL PROTECTED]> wrote:
>Just a kind remark, there is no such thing called memory leak in Java.
>Memory used by java is automatically managed by VM, mostly out of the
>control and will of the programmers.
The garbage collector only collects unreferenced data, therefore there are
such things as memory leaks if you maintain a reference to the data. For
instance, by creating a static variable or a thread and then stuffing data
into the variable or into a member of the thread. For instance,
static Vector allMemory = new Vector();
...
for (;;) {
allMemory.addElement(new String("what a waste of memory"));
}
...
There can also be infinite loops that gobble up memory:
while (! done) {
... allocate some memory ...
... forget to change condition leading to exit from loop ...
}
Eventually this will throw an OutOfMemory exception, thus exiting the loop.
In this second case the memory will be reclaimed by the GC.
-- Ari Halberstadt mailto:[EMAIL PROTECTED] <http://www.magiccookie.com/>
PGP public key available at <http://www.magiccookie.com/pgpkey.txt>
----------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://www.working-dogs.com/>
Problems?: [EMAIL PROTECTED]