Daniel Dekany wrote:

Sunday, December 14, 2003, 10:04:10 PM, Stephen McConnell wrote:



Daniel Dekany wrote:


[snip]


Why? Is it a soft reference cleared exactly when the referenced object
is finalized? Is this two act united to form an atomic operation? I
think they are not, so it is possible that the soft ref. cleared earlier
than finalization is called (but please point out if the JVM spec.
states something that prevents this to happen), so it is till not
ensured that finalize() will be called before the VM terminates.



The soft ref is to the proxy. The proxy always has a valid refernce to the component. If the soft ref returns null, then the object referenced by the soft ref (the proxy) has been finalized (or according to the spec is at least queued for finalization). This means that by defintion the proxy has or is about to decommission the component.



Correct... (IMO)




If the value retured from the ref is not null - then we have a
reference (in a thread) to the proxy and the proxy has a hard
reference to the component and we trigger decommissioning directly.



Correct... (IMO)




I.e. if the ref returns null - we know that it is in the pipeline for finalization - otherwise we take care of it manually.



Correct. (IMO)


So what? If ref.get() == null, you only know that it is "at least queued
for finalization". But, again, it does not means that the finalization
will actually happen. Because, even if the object is queued for
finalization, the VM can terminate before actually doing that. Or is it
the VM required to finalize all queued objects before terminating?
(Point that sentence in the specs.)


So the question is - "is a JVM required to invoke finalize (where finalize is overriden) on all objects objects on the stack for existing (or the more specific case of invoking finalize on all objects in the finalizable queue). My understanding is that "best efforts" can be assumed relative to the JLS, but that implementions take this to extreme imposed by the application.


In particular we have the following (implementation) reference:

System.runFinalization():

       Calling this method suggests that the Java Virtual
       Machine expend effort toward running the |finalize|
       methods of objects that have been found to be discarded
       but whose |finalize| methods have not yet been run. When
       control returns from the method call, the Java Virtual
       Machine has made a best effort to complete all outstanding
       finalizations.

However, we also have the following (implementation) statement in

Runtime.addShutdownHook():

       When the virtual machine begins its shutdown sequence it
       will start all registered shutdown hooks in some unspecified
       order and let them run concurrently. When all the hooks have
       finished it will then run all uninvoked finalizers if
       finalization-on-exit has been enabled. Finally, the virtual
       machine will halt.


My interpritation here is that the notion of "best effort" can be assumed (but that its not gauranteed due to constrains implied by the underlying operating system) - which means that you have a situation where active release is desirable.


Stephen.

--

Stephen J. McConnell
mailto:[EMAIL PROTECTED]

|------------------------------------------------|
| Magic by Merlin                                |
| Production by Avalon                           |
|                                                |
| http://avalon.apache.org/merlin                |
| http://dpml.net/                               |
|------------------------------------------------|





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



Reply via email to