Godmar Back wrote:
> 
> > Ari wrote:
> > >I have a static counter attribute, and I do not want to see it gc'ed.
> > >Am I missing something ?
> > >
> > >Jean-Luc
> >
> > If it's static it won't be GC'd.
> >
> 
> I may misunderstand what you're talking about here, but
> static members of classes are gc'd like any other object in Java
> when it becomes unreachable.  For a static member to become
> unreachable, its class must have become unreachable.  If class gc
> is disabled, no class ever becomes unreachable, hence no static
> members are ever gc'd.
> 
> For this reason, I don't think using a static member variable as a persistent
> counter makes sense by itself.  While it will survive multiple requests,
> it won't survive class reloading.  

I agree. I just made a quick cut & paste from am existing benchmark
congiguration.
And in the sample, yes, I did use a static counter as a "process
lifetime persistent" counter, and at the same time I had no need for
class reloading, as this was only a benchmark.
But maybe we should clarify this point, as people do not agree on this : 
class gc destroys its static attributes or not. 
I do think so, but now I'm not 100% sure.

Anyway, as I ran the benchmark with millions hits, I didn't notice any
leak.
Maybe there was one, but small ? (again my classes did not change).

Can someone clarify this ?
 
> This was Class reloading creates a new instance of
> that static member variable.  If you disable class gc, the old instance
> will be floating garbage, hence the memory leak.
> 
> I think what you'll need is some mechanism to write out your counter to
> disk when the class is gc --- this could be a finalizer --- and some
> mechanism to read it back in when your class gets initialized.
> This could be done in a <clinit> method (as in static { ... });
> 
Using a static attibute as a (process lifetime persistent) counter makes
sense to me, and I don't like the idea of writing it to disk to keep it
up. I admit that if the class is reloaded it will be zeroed, and that's
why I used the -noclassgc.

Jean-Luc


----------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html/>
Problems?:           [EMAIL PROTECTED]

Reply via email to