Yes, your points and examples are well-taken.
What I tried to explain in my earlier response is that, if your program does
have to process a large number of objects, say 2500 objects and each object has
a size of 20KB, then VM just need to have 2500*20KB = 50 MB. "out of memory"
is exactly what I encountered when I run my servlet using JDK 1.2 on a Sparc
machine, and I cannot just do anything about it except to increase the initial
and maximum memory for Java VM. I simply could not figure out a way to
programatically reduce the memory usage. Those 2500 objects after creation
just stayed around until VM decide to have mercy and do some garbage
collection.
Well, I could use Runtime class methods to explicitly kick off garbage
collection, but still no control of how much to reclaim. It does help a bit
for reducing the occupied memory by Java VM.
But, then maybe there is a way to dispose those 2500 data objects ?
regards,
Ari Halberstadt wrote:
> 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]
--
Metaphase Technology Group | voice: (651) 482-2966
4201 Lexington Ave N, Arden Hills, MN 55126
----------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://www.working-dogs.com/>
Problems?: [EMAIL PROTECTED]