[Biojava-dev] [BioJava - Bug #3345] Static object cache in SimpleRichObjectBuilder causing memory leak
redmine at redmine.open-bio.org
redmine at redmine.open-bio.org
Thu Apr 26 15:21:37 UTC 2012
Issue #3345 has been updated by Tjeerd Boerman.
I just noticed this has been fixed in BioJava 1.8.2. Sorry for the confusion - I could only find 1.8.1 on the wiki so I was still using that version. Please close this report!
----------------------------------------
Bug #3345: Static object cache in SimpleRichObjectBuilder causing memory leak
https://redmine.open-bio.org/issues/3345
Author: Tjeerd Boerman
Status: New
Priority: Normal
Assignee: biojava-dev list
Category: bio
Target version: BioJava 1.8 - legacy
URL:
I encountered a memory problem when parsing many Genbank files with the Biojava 1.8.1. The parsed files were protein GPFF (GenPept Flat File format) files from the latest RefSeq release. The application tried to parse millions of protein sequences from these files, but an OutOfMemoryException would always occur after some time. The used heap space would gradually increase from a couple hundred megabytes to over 1.5 GB, until the heap could grow no further. Upon inspection I discovered a HashMap in RichSequenceBuilder was the culprit:
<pre>
public class SimpleRichObjectBuilder implements RichObjectBuilder {
private static Map objects = new HashMap();
public Object buildObject(Class clazz, List paramsList) {
...
// return the constructed object from the hashmap if there already
if (contents.containsKey(ourParamsList)) return contents.get(ourParamsList);
...
// Instantiate it with the parameters
Object o = c.newInstance(ourParamsList.toArray());
// store it for later in the singleton map
contents.put(ourParamsList, o);
...
}
}
</pre>
It seems the *objects* Map in SimpleRichSequenceBuilder is used as a static cache for objects, but when many different objects are created this cache grows out of control. I am unsure if this is a 'true' bug, but for my application it was a definite problem. My fix was to simply comment out the *contents.put()* statement, but I'm sure there is a better way to resolve this - perhaps by making the use of the cache optional through a configuration option.
--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here and login: http://redmine.open-bio.org
More information about the biojava-dev
mailing list