
|
If you were logged in you would be able to see more operations.
|
|
|
GeoTools
Created: 07/Mar/08 03:13 PM
Updated: 04/Aug/08 04:39 PM
|
|
| Component/s: |
core coverage
|
| Affects Version/s: |
2.5-M2
|
| Fix Version/s: |
2.5-M3
|
|
|
Issue Links:
|
dependent
|
|
|
|
This issue is depended upon by:
|
|
GEOS-1795
GeoServer is not cleaning testing data dirs using coverages on windows
|
|
|
|
|
|
|
|
AbstractGridCoverage2DReader and GridCoverage2D should define a finalize method
|
|
Description
|
AbstractGridCoverage2DReader and GridCoverage2D should define a finalize method |
Show » |
|
http://www-128.ibm.com/developerworks/java/library/j-jtctips/j-jtc0319a.html
In short, finalizers are useful for releasing some native resources that could not be otherwise released by the garbage collector. But except for those few cases, it seems to cause more hurt than good. Finalizers put more pressure on the garbage collector (a finalized object must first be pushed in a finalizer queue, waits for its execution in an undetermined thread - which pose thread safety issues -, then wait for a new garbage collection cycle before they get effectively collected). Every fields hold by the GridCoverage2D may be retained longuer than they would otherwise be, including the PlanarImage reference (which I assume is the target of the proposed finalizer method).
I assume that the intend was to invoke PlanarImage.dispose() on GridCoverage2D finalization. In addition of increasing garbage collector pressure (which may leads to the opposite of the intented effect, because of longer retention of the image reference), it is also unsafe. It would be safe if the image reference was private and if no getter method could return, directly or indirectly, a reference to this image. But this is not the case. The PlanarImage can still in use by anyone outside the GridCoverage2D class, for example the result of a Resample operation.
We could invoke GridCoverage2D.dispose(false) which disposes the PlanarImage only conservatively, but this check is approximative and can be wrong. With an explicit GridCoverage2D.dispose(boolean) method, developpers invoke it only if they want. With a finalizer() method, it would be invoked in all cases, probably causing hard-to-track bugs in applications using the PlanarImage outside the GridCoverage2D.
And most of all, the benefit compared to waiting for the garbage collector to collect the PlanarImage seems very hypothetical - it may actually be counter-productive in my understanding of the articles suggesting to avoid finalizers.