a variety of possible memory leak fixes

pull/1/head
Michael Peter Christen 13 years ago
parent d7eb18cdf2
commit 00f2df1120

@ -453,6 +453,7 @@ public class Domains {
globalHosts = null; globalHosts = null;
} else try { } else try {
globalHosts = new KeyList(globalHostsnameCache); globalHosts = new KeyList(globalHostsnameCache);
Log.logInfo("Domains", "loaded globalHosts cache of hostnames, size = " + globalHosts.size());
} catch (final IOException e) { } catch (final IOException e) {
globalHosts = null; globalHosts = null;
} }

@ -89,7 +89,7 @@ public class WeakPriorityBlockingQueue<E> {
/** /**
* get the number of elements that had been drained so far and are wainting * get the number of elements that had been drained so far and are waiting
* in a list to get enumerated with element() * in a list to get enumerated with element()
* @return * @return
*/ */
@ -103,7 +103,7 @@ public class WeakPriorityBlockingQueue<E> {
* @return * @return
*/ */
public synchronized int sizeAvailable() { public synchronized int sizeAvailable() {
return this.queue.size() + this.drained.size(); return Math.min(this.maxsize, this.queue.size() + this.drained.size());
} }
/** /**
@ -170,7 +170,7 @@ public class WeakPriorityBlockingQueue<E> {
final Element<E> element = this.queue.first(); final Element<E> element = this.queue.first();
assert element != null; assert element != null;
this.queue.remove(element); this.queue.remove(element);
this.drained.add(element); if (this.drained.size() < this.maxsize) this.drained.add(element);
assert this.queue.size() >= this.enqueued.availablePermits() : "(take) queue.size() = " + this.queue.size() + ", enqueued.availablePermits() = " + this.enqueued.availablePermits(); assert this.queue.size() >= this.enqueued.availablePermits() : "(take) queue.size() = " + this.queue.size() + ", enqueued.availablePermits() = " + this.enqueued.availablePermits();
return element; return element;
} }
@ -289,14 +289,17 @@ public class WeakPriorityBlockingQueue<E> {
public long weight; public long weight;
public E element; public E element;
@Override
public long getWeight() { public long getWeight() {
return this.weight; return this.weight;
} }
@Override
public E getElement() { public E getElement() {
return this.element; return this.element;
} }
@Override
public boolean equals(Element<E> o) { public boolean equals(Element<E> o) {
return this.element.equals(o.getElement()); return this.element.equals(o.getElement());
} }
@ -308,7 +311,7 @@ public class WeakPriorityBlockingQueue<E> {
@Override @Override
public String toString() { public String toString() {
return element.toString() + "/" + weight; return this.element.toString() + "/" + this.weight;
} }
} }
@ -323,10 +326,12 @@ public class WeakPriorityBlockingQueue<E> {
this.weight = weight; this.weight = weight;
} }
@Override
public int compare(NaturalElement<E> o1, NaturalElement<E> o2) { public int compare(NaturalElement<E> o1, NaturalElement<E> o2) {
return o1.compareTo(o2); return o1.compareTo(o2);
} }
@Override
public int compareTo(NaturalElement<E> o) { public int compareTo(NaturalElement<E> o) {
if (this.element == o.getElement()) return 0; if (this.element == o.getElement()) return 0;
if (this.element.equals(o.getElement())) return 0; if (this.element.equals(o.getElement())) return 0;
@ -352,10 +357,12 @@ public class WeakPriorityBlockingQueue<E> {
this.weight = weight; this.weight = weight;
} }
@Override
public int compare(ReverseElement<E> o1, ReverseElement<E> o2) { public int compare(ReverseElement<E> o1, ReverseElement<E> o2) {
return o1.compareTo(o2); return o1.compareTo(o2);
} }
@Override
public int compareTo(ReverseElement<E> o) { public int compareTo(ReverseElement<E> o) {
if (this.element == o.getElement()) return 0; if (this.element == o.getElement()) return 0;
if (this.element.equals(o.getElement())) return 0; if (this.element.equals(o.getElement())) return 0;

@ -37,13 +37,13 @@ public final class HashARC<K, V> extends SimpleARC<K, V> implements Map<K, V>, I
public HashARC(final int cacheSize) { public HashARC(final int cacheSize) {
this.cacheSize = cacheSize / 2; this.cacheSize = cacheSize / 2;
super.levelA = Collections.synchronizedMap(new LinkedHashMap<K, V>(cacheSize, 0.1f, accessOrder) { super.levelA = Collections.synchronizedMap(new LinkedHashMap<K, V>(1, 0.1f, accessOrder) {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override protected boolean removeEldestEntry(final Map.Entry<K, V> eldest) { @Override protected boolean removeEldestEntry(final Map.Entry<K, V> eldest) {
return size() > HashARC.this.cacheSize; return size() > HashARC.this.cacheSize;
} }
}); });
this.levelB = Collections.synchronizedMap(new LinkedHashMap<K, V>(cacheSize, 0.1f, accessOrder) { this.levelB = Collections.synchronizedMap(new LinkedHashMap<K, V>(1, 0.1f, accessOrder) {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override protected boolean removeEldestEntry(final Map.Entry<K, V> eldest) { @Override protected boolean removeEldestEntry(final Map.Entry<K, V> eldest) {
return size() > HashARC.this.cacheSize; return size() > HashARC.this.cacheSize;

@ -76,6 +76,10 @@ public class KeyList implements Iterable<String> {
} }
public int size() {
return this.keys.size();
}
public boolean contains(final String key) { public boolean contains(final String key) {
return this.keys.containsKey(key.trim().toLowerCase()); return this.keys.containsKey(key.trim().toLowerCase());
} }

@ -98,6 +98,7 @@ public final class HandleMap implements Iterable<Row.Entry> {
is.close(); is.close();
is = null; is = null;
assert this.index.size() == file.length() / (keylength + idxbytes); assert this.index.size() == file.length() / (keylength + idxbytes);
trim();
} }
public void trim() { public void trim() {
@ -415,6 +416,7 @@ public final class HandleMap implements Iterable<Row.Entry> {
return this.result.get(); return this.result.get();
} }
@Override
public final HandleMap call() throws IOException { public final HandleMap call() throws IOException {
try { try {
finishloop: while (true) { finishloop: while (true) {
@ -439,7 +441,8 @@ public final class HandleMap implements Iterable<Row.Entry> {
} }
} }
public Iterator<Row.Entry> iterator() { @Override
public Iterator<Row.Entry> iterator() {
return rows(true, null); return rows(true, null);
} }
} }

@ -473,6 +473,7 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {
} }
} }
} }
references.trim();
System.out.println("CELL REFERENCE COLLECTION finished"); System.out.println("CELL REFERENCE COLLECTION finished");
return references; return references;
} }

@ -187,6 +187,7 @@ public class Table implements Index, Iterable<Row.Entry> {
} }
} }
} }
this.index.trim();
// open the file // open the file
this.file = new BufferedRecords(new Records(tablefile, rowdef.objectsize), this.buffersize); this.file = new BufferedRecords(new Records(tablefile, rowdef.objectsize), this.buffersize);
@ -594,6 +595,7 @@ public class Table implements Index, Iterable<Row.Entry> {
* @throws IOException * @throws IOException
* @throws RowSpaceExceededException * @throws RowSpaceExceededException
*/ */
@Override
public boolean put(final Entry row) throws IOException, RowSpaceExceededException { public boolean put(final Entry row) throws IOException, RowSpaceExceededException {
assert row != null; assert row != null;
if (this.file == null || row == null) return true; if (this.file == null || row == null) return true;
@ -702,6 +704,7 @@ public class Table implements Index, Iterable<Row.Entry> {
} }
} }
@Override
public boolean delete(final byte[] key) throws IOException { public boolean delete(final byte[] key) throws IOException {
return remove(key) != null; return remove(key) != null;
} }

@ -109,8 +109,8 @@ public class SnippetProcess {
this.urlRetrievalAllTime = 0; this.urlRetrievalAllTime = 0;
this.snippetComputationAllTime = 0; this.snippetComputationAllTime = 0;
this.result = new WeakPriorityBlockingQueue<ResultEntry>(-1); // this is the result, enriched with snippets, ranked and ordered by ranking this.result = new WeakPriorityBlockingQueue<ResultEntry>(Math.max(1000, 10 * query.itemsPerPage())); // this is the result, enriched with snippets, ranked and ordered by ranking
this.images = new WeakPriorityBlockingQueue<MediaSnippet>(-1); this.images = new WeakPriorityBlockingQueue<MediaSnippet>(Math.max(1000, 10 * query.itemsPerPage()));
// snippets do not need to match with the complete query hashes, // snippets do not need to match with the complete query hashes,
// only with the query minus the stopwords which had not been used for the search // only with the query minus the stopwords which had not been used for the search

@ -206,10 +206,10 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
if (de.anomic.crawler.Cache.has(url.hash())) { if (de.anomic.crawler.Cache.has(url.hash())) {
// get the sentences from the cache // get the sentences from the cache
final Request request = loader.request(url, true, reindexing); final Request request = loader == null ? null : loader.request(url, true, reindexing);
Response response; Response response;
try { try {
response = loader == null ? null : loader.load(request, CacheStrategy.CACHEONLY, true); response = loader == null || request == null ? null : loader.load(request, CacheStrategy.CACHEONLY, true);
} catch (IOException e1) { } catch (IOException e1) {
response = null; response = null;
} }

Loading…
Cancel
Save