Friday, December 12, 2003, 7:37:24 PM, Stephen McConnell wrote:

> Daniel Dekany wrote:
>
>>Friday, December 12, 2003, 5:09:03 PM, Timothy Bennett wrote:
>>
>>[snip]
>>  
>>
>>>The Sun GC guys highly discourage the use of pooling due to alot of
>>>improvements and optimizations in the JDK1.4+ garbage collector.  The 
>>>JDK1.5 GC will even smarter and self-tuning.  The only exception to the 
>>>"do-not-pool" recommendation is when you have objects that are very 
>>>expensive to create, such as database connections.
>>>    
>>>
>>
>>How to invoke the life-cycle events (dispose, etc.) when the GC is
>>responsible to releases the component? Stephen McConnell said that it
>>works so in Merlin, but I'm pessimistic about that it can be implemented
>>correctly on Java platform. What's the trick?
>>
>
> :-)
>
> The trick is that a proxy is generated that holds a reference to the 
> actual component.  If the proxy is finalized it knows that the component 
> it is referencing has no outstanding references - but the proxy has a 
> reference to the appliance managing the component - so the proxy invokes 
> the decommissioning cycle on the appliance which invokes decomissioning 
> actions on the component which results in component disposal.

It's not accident that I asked this. It's something I waned to solve
earlier. This proxy trick was occurred to me, but I found that it is not
correct:

a) It is possible that the finalize() of the component, or the
finalize() of any other object referred by the component is already
invoked before the finalize() of the proxy is invoked. So dispose() will
find itself in an abnormal situation, where some of the object are
already finalized, or even worst, just being concurrently finalized in
another thread.

b) When the VM *normally* shutted down, the finalize() of some otherwise
unreferenced objects will not be called, so the component will be
disintegrated without receiving dispose event. Yes, there is
System.runFinalizersOnExit but... well... in the JavaDocs: "Deprecated.
This method is inherently unsafe."


(Also, note that as I said earlier in this thread, seems to me that with
Merling 3.2 transient objects were never GC-ed. Maybe that's a bug.)

-- 
Best regards,
 Daniel Dekany



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to