You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Otis Gospodnetic <ot...@yahoo.com> on 2004/02/20 14:17:01 UTC

Lucene's finalizeable objects

An interesting article from a person known to lucene-dev:

  http://www-106.ibm.com/developerworks/library/j-jtp01274.html

I only skimmed the article, and only read the section about
finalizeable objects.

Lucene has several:

$ ffjg finalize
./index/IndexWriter.java:  protected void finalize() throws IOException
{
./index/IndexReader.java:  protected final void finalize() throws
IOException {
./store/FSDirectory.java:  protected final void finalize() throws
IOException {
./store/FSDirectory.java:  protected final void finalize() throws
IOException {

Then I read the following, and noticed the
"FinalizeDoesNotCallSuperFinalize" rule:

  http://pmd.sourceforge.net/rules/finalizers.html

Then I looked at Lucene's finalize() methods and noticed that none of
them call super.finalize().

Now I'm wondering if they should.
I don't know enough about it to make strong statements, only point this
out to those who may know more, and can offer advice.

Otis


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Re: Lucene's finalizeable objects

Posted by Doug Cutting <cu...@apache.org>.
Otis Gospodnetic wrote:
> An interesting article from a person known to lucene-dev:
> 
>   http://www-106.ibm.com/developerworks/library/j-jtp01274.html
> 
> I only skimmed the article, and only read the section about
> finalizeable objects.
> 
> Lucene has several:
> 
> $ ffjg finalize
> ./index/IndexReader.java:  protected final void finalize() throws
> ./store/FSDirectory.java:  protected final void finalize() throws

These are coarse-grained objects, things which are not created in tight 
loops.  So I don't think these abuse finalize(), but rather use it as 
intended, to return OS resources which cannot be returned otherwise.

> Then I read the following, and noticed the
> "FinalizeDoesNotCallSuperFinalize" rule:
> 
>   http://pmd.sourceforge.net/rules/finalizers.html
> 
> Then I looked at Lucene's finalize() methods and noticed that none of
> them call super.finalize().

If you're subclassing something that has a finalize method then this 
makes sense, and it's probably good style in any case.  But Object's 
finalize method has an empty body, so calling super.finalize() in either 
of the above cases would have only a stylistic effect and not change 
behaviour at all.

Doug

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org