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;
} else try {
globalHosts = new KeyList(globalHostsnameCache);
Log.logInfo("Domains", "loaded globalHosts cache of hostnames, size = " + globalHosts.size());
} catch (final IOException e) {
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()
* @return
*/
@ -103,7 +103,7 @@ public class WeakPriorityBlockingQueue<E> {
* @return
*/
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();
assert element != null;
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();
return element;
}
@ -289,14 +289,17 @@ public class WeakPriorityBlockingQueue<E> {
public long weight;
public E element;
@Override
public long getWeight() {
return this.weight;
}
@Override
public E getElement() {
return this.element;
}
@Override
public boolean equals(Element<E> o) {
return this.element.equals(o.getElement());
}
@ -308,7 +311,7 @@ public class WeakPriorityBlockingQueue<E> {
@Override
public String toString() {
return element.toString() + "/" + weight;
return this.element.toString() + "/" + this.weight;
}
}
@ -323,10 +326,12 @@ public class WeakPriorityBlockingQueue<E> {
this.weight = weight;
}
@Override
public int compare(NaturalElement<E> o1, NaturalElement<E> o2) {
return o1.compareTo(o2);
}
@Override
public int compareTo(NaturalElement<E> o) {
if (this.element == o.getElement()) return 0;
if (this.element.equals(o.getElement())) return 0;
@ -352,10 +357,12 @@ public class WeakPriorityBlockingQueue<E> {
this.weight = weight;
}
@Override
public int compare(ReverseElement<E> o1, ReverseElement<E> o2) {
return o1.compareTo(o2);
}
@Override
public int compareTo(ReverseElement<E> o) {
if (this.element == 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) {
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;
@Override protected boolean removeEldestEntry(final Map.Entry<K, V> eldest) {
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;
@Override protected boolean removeEldestEntry(final Map.Entry<K, V> eldest) {
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) {
return this.keys.containsKey(key.trim().toLowerCase());
}

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

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

@ -187,6 +187,7 @@ public class Table implements Index, Iterable<Row.Entry> {
}
}
}
this.index.trim();
// open the file
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 RowSpaceExceededException
*/
@Override
public boolean put(final Entry row) throws IOException, RowSpaceExceededException {
assert row != null;
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 {
return remove(key) != null;
}

@ -109,8 +109,8 @@ public class SnippetProcess {
this.urlRetrievalAllTime = 0;
this.snippetComputationAllTime = 0;
this.result = new WeakPriorityBlockingQueue<ResultEntry>(-1); // this is the result, enriched with snippets, ranked and ordered by ranking
this.images = new WeakPriorityBlockingQueue<MediaSnippet>(-1);
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>(Math.max(1000, 10 * query.itemsPerPage()));
// 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

@ -206,10 +206,10 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
if (de.anomic.crawler.Cache.has(url.hash())) {
// 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;
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) {
response = null;
}

Loading…
Cancel
Save