You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2006/03/05 00:18:48 UTC

svn commit: r383220 - /jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java

Author: scolebourne
Date: Sat Mar  4 15:18:46 2006
New Revision: 383220

URL: http://svn.apache.org/viewcvs?rev=383220&view=rev
Log:
Add finalize method

Modified:
    jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java

Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java?rev=383220&r1=383219&r2=383220&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java (original)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java Sat Mar  4 15:18:46 2006
@@ -150,6 +150,14 @@
         throw new UnsupportedOperationException("Remove unsupported on LineIterator");
     }
 
+    /**
+     * Finalize which closes the underlying reader.
+     * Do not rely on this method to handle cleanup - call closeQuietly yourself.
+     */
+    protected void finalize() throws Throwable {
+        close();
+    }
+
     //-----------------------------------------------------------------------
     /**
      * Closes the iterator, handling null and ignoring exceptions.



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


Re: svn commit: r383220 - /jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java

Posted by Sandy McArthur <sa...@gmail.com>.
I don't see how this benefits anything and it has a negative effect on
the whole JVM.

I would think it's common to use a LineIterator entirely in one method
which means an instance could live entirely in the eden space. The
presence of a finalizer method causes the JVM to register the object
in a queue that eventually executes the finalize method. Since this is
another thread this forces the JVM to promote the object from eden
space to old space in the heap and it requires more work to garbage
collect old space compared to the eden space.

I can dig up more but I found this with a quick google:
http://www-128.ibm.com/developerworks/java/library/j-jtctips/j-jtc0319a.html
http://www.javaperformancetuning.com/news/interview041.shtml (see last Q&A)

Also, I don't see any "resource leak" in my read of the LineIterator
code. I see a resource clean up delay, if there is such a concept, but
no leak.
http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java?view=markup

On 3/4/06, scolebourne@apache.org <sc...@apache.org> wrote:
> Author: scolebourne
> Date: Sat Mar  4 15:18:46 2006
> New Revision: 383220
>
> URL: http://svn.apache.org/viewcvs?rev=383220&view=rev
> Log:
> Add finalize method
>
> Modified:
>     jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java
>
> Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java
> URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java?rev=383220&r1=383219&r2=383220&view=diff
> ==============================================================================
> --- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java (original)
> +++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java Sat Mar  4 15:18:46 2006
> @@ -150,6 +150,14 @@
>          throw new UnsupportedOperationException("Remove unsupported on LineIterator");
>      }
>
> +    /**
> +     * Finalize which closes the underlying reader.
> +     * Do not rely on this method to handle cleanup - call closeQuietly yourself.
> +     */
> +    protected void finalize() throws Throwable {
> +        close();
> +    }
> +
>      //-----------------------------------------------------------------------
>      /**
>       * Closes the iterator, handling null and ignoring exceptions.
>


--
Sandy McArthur

"He who dares not offend cannot be honest."
- Thomas Paine

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