Skip to content

Commit

Permalink
removed finalize methods because of a hint in
Browse files Browse the repository at this point in the history
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
  • Loading branch information
orbiter committed Apr 23, 2010
1 parent bfa35d6 commit 4cd5418
Show file tree
Hide file tree
Showing 12 changed files with 4 additions and 64 deletions.
5 changes: 0 additions & 5 deletions source/de/anomic/crawler/CrawlProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ public void close() {
this.profileTable = null;
}

@Override
public void finalize() {
this.close();
}

public int size() {
return profileTable.size();
}
Expand Down
10 changes: 0 additions & 10 deletions source/de/anomic/http/server/ResponseContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,4 @@ public String getHttpVer() {
public void setAccountingName(final String accName) {
incomingAccountingName = accName;
}

/*
* (non-Javadoc)
*
* @see java.lang.Object#finalize()
*/
@Override
protected void finalize() {
closeStream();
}
}
4 changes: 0 additions & 4 deletions source/de/anomic/server/serverCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,10 +656,6 @@ public void run() {

}

protected void finalize() {
this.close();
}

private void listen() {
try {
// start dialog
Expand Down
5 changes: 0 additions & 5 deletions source/net/yacy/document/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,5 @@ public void close() {
}
}
}

protected void finalize() throws Throwable {
this.close();
super.finalize();
}

}
5 changes: 0 additions & 5 deletions source/net/yacy/document/parser/html/AbstractScraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ public void close() {
tags1 = null;
}

@Override
protected void finalize() {
close();
}

}


5 changes: 0 additions & 5 deletions source/net/yacy/document/parser/html/AbstractTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,5 @@ public void close() {
tags0 = null;
tags1 = null;
}

@Override
protected void finalize() {
close();
}

}
7 changes: 0 additions & 7 deletions source/net/yacy/document/parser/html/TransformerWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,6 @@ public void flush() throws IOException {
// 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 {
final char quotechar = (inSingleQuote) ? singlequote : doublequote;
if (buffer != null) {
Expand Down
6 changes: 4 additions & 2 deletions source/net/yacy/kelondro/index/RowSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ public final static RowSet importRowSet(final byte[] b, final Row rowdef) {
final int orderbound = (int) NaturalOrder.decodeLong(b, 10, 4);
assert orderbound >= 0 : "orderbound = " + orderbound;
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;
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);
return new RowSet(rowdef);
}
Expand Down
6 changes: 0 additions & 6 deletions source/net/yacy/kelondro/io/ByteCountInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,4 @@ public final static void resetCount() {
byteCountInfo.clear();
}
}

protected final void finalize() throws Throwable {
if (!this.finished)
finish();
super.finalize();
}
}
5 changes: 0 additions & 5 deletions source/net/yacy/kelondro/io/ByteCountOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,4 @@ public final void finish() {
}
}

protected final void finalize() throws Throwable {
if (!this.finished)
finish();
super.finalize();
}
}
4 changes: 0 additions & 4 deletions source/net/yacy/kelondro/rwi/ReferenceIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ public void close() {
if (blobs != null) this.blobs.close();
blobs = null;
}

protected void finalize() {
this.close();
}

public CloneableIterator<ReferenceContainer<ReferenceType>> clone(Object modifier) {
if (blobs != null) this.blobs.close();
Expand Down
6 changes: 0 additions & 6 deletions source/net/yacy/kelondro/util/XMLTables.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,4 @@ public void close() throws IOException {
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();
}

}

0 comments on commit 4cd5418

Please sign in to comment.