removed finalize methods because of a hint in

http://java.sun.com/javase/6/webnotes/trouble/TSG-VM/html/memleaks.html#gbyvh

The finalize method prevents that the memory, used by the objects containing the finalize method, is collected and available for the garbage collector. Instead, the memory allocated by such classes are enqueued to a java-internal finalize queue runner. This slows down all operations that uses a lot of object containing finalize methods.

this fix does not remove all finalize method, but such that may be used for throw-away objects that are allocated many times. This should cause a better run-time performance and less OutOfMemoryErrors 

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6835 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
orbiter 2010-04-23 09:32:29 +00:00
parent bfa35d6d20
commit 4cd5418963
12 changed files with 4 additions and 64 deletions

View File

@ -85,11 +85,6 @@ public class CrawlProfile {
this.profileTable = null; this.profileTable = null;
} }
@Override
public void finalize() {
this.close();
}
public int size() { public int size() {
return profileTable.size(); return profileTable.size();
} }

View File

@ -176,14 +176,4 @@ public class ResponseContainer {
public void setAccountingName(final String accName) { public void setAccountingName(final String accName) {
incomingAccountingName = accName; incomingAccountingName = accName;
} }
/*
* (non-Javadoc)
*
* @see java.lang.Object#finalize()
*/
@Override
protected void finalize() {
closeStream();
}
} }

View File

@ -656,10 +656,6 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
} }
protected void finalize() {
this.close();
}
private void listen() { private void listen() {
try { try {
// start dialog // start dialog

View File

@ -590,10 +590,5 @@ dc_rights
} }
} }
} }
protected void finalize() throws Throwable {
this.close();
super.finalize();
}
} }

View File

@ -95,11 +95,6 @@ public abstract class AbstractScraper implements Scraper {
tags1 = null; tags1 = null;
} }
@Override
protected void finalize() {
close();
}
} }

View File

@ -67,10 +67,5 @@ public abstract class AbstractTransformer implements Transformer {
tags0 = null; tags0 = null;
tags1 = null; tags1 = null;
} }
@Override
protected void finalize() {
close();
}
} }

View File

@ -530,13 +530,6 @@ public final class TransformerWriter extends Writer {
// if you want to flush all, call close() at end of writing; // if you want to flush all, call close() at end of writing;
} }
@Override
protected void finalize() throws IOException {
// if we are forced to close, we of course flush the buffer first,
// then close the connection
close();
}
public void close() throws IOException { public void close() throws IOException {
final char quotechar = (inSingleQuote) ? singlequote : doublequote; final char quotechar = (inSingleQuote) ? singlequote : doublequote;
if (buffer != null) { if (buffer != null) {

View File

@ -76,9 +76,11 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
final int orderbound = (int) NaturalOrder.decodeLong(b, 10, 4); final int orderbound = (int) NaturalOrder.decodeLong(b, 10, 4);
assert orderbound >= 0 : "orderbound = " + orderbound; assert orderbound >= 0 : "orderbound = " + orderbound;
if (orderbound < 0) return new RowSet(rowdef); // error if (orderbound < 0) return new RowSet(rowdef); // error
final byte[] chunkcache = new byte[size * rowdef.objectsize]; long alloc = ((long) size) * ((long) rowdef.objectsize);
assert alloc <= Integer.MAX_VALUE : "alloc = " + alloc;
final byte[] chunkcache = new byte[(int) alloc];
//assert b.length - exportOverheadSize == size * rowdef.objectsize : "b.length = " + b.length + ", size * rowdef.objectsize = " + size * rowdef.objectsize; //assert b.length - exportOverheadSize == size * rowdef.objectsize : "b.length = " + b.length + ", size * rowdef.objectsize = " + size * rowdef.objectsize;
if (b.length - exportOverheadSize != size * rowdef.objectsize) { if (b.length - exportOverheadSize != alloc) {
Log.logSevere("RowSet", "exportOverheadSize wrong: b.length = " + b.length + ", size * rowdef.objectsize = " + size * rowdef.objectsize); Log.logSevere("RowSet", "exportOverheadSize wrong: b.length = " + b.length + ", size * rowdef.objectsize = " + size * rowdef.objectsize);
return new RowSet(rowdef); return new RowSet(rowdef);
} }

View File

@ -143,10 +143,4 @@ public final class ByteCountInputStream extends FilterInputStream {
byteCountInfo.clear(); byteCountInfo.clear();
} }
} }
protected final void finalize() throws Throwable {
if (!this.finished)
finish();
super.finalize();
}
} }

View File

@ -132,9 +132,4 @@ public final class ByteCountOutputStream extends BufferedOutputStream {
} }
} }
protected final void finalize() throws Throwable {
if (!this.finished)
finish();
super.finalize();
}
} }

View File

@ -82,10 +82,6 @@ public class ReferenceIterator <ReferenceType extends Reference> implements Clon
if (blobs != null) this.blobs.close(); if (blobs != null) this.blobs.close();
blobs = null; blobs = null;
} }
protected void finalize() {
this.close();
}
public CloneableIterator<ReferenceContainer<ReferenceType>> clone(Object modifier) { public CloneableIterator<ReferenceContainer<ReferenceType>> clone(Object modifier) {
if (blobs != null) this.blobs.close(); if (blobs != null) this.blobs.close();

View File

@ -164,10 +164,4 @@ public class XMLTables {
commit(true); commit(true);
} }
// we finalize the operation by saving everything throug the scheduler
// this method is called by the java GC bevore it destroys the object
protected void finalize() throws IOException {
close();
}
} }