Memory leak/to much retained in WorkSpaceCache?
bwallis42 Sep 1, 2012 8:35 PMRunning 3.0.0.Beta3 on JDK 1.6.0_33.
I have a bit of code (shown below) that I am running against a populated repository that has 14524 nodes that are a subclass of nt:resource. These nodes each have a binary value in the jcr:data attribute that is 1024 bytes long. The code I run just does a query for all the nt:resource nodes (select * from [nt:resource]) then iterates through them reading the binary data from each and discarding it. Total binary data read from the nodes is about 14 MBytes.
When I run the download() method the heap of the JBoss JVM grows by about 430MBytes and this is never returned to the heap, it seems to be retained in the WorkSpaceCache (although I could be completly wrong about that, that is just where I traced a lot of memory references to using jprofiler).
Is there something missing in the code shown that I should be closing or clearing or something? Running the code a second time does not increase the allocation (and in fact it runs very fast the second time).
{code}
public String download() {
Session session = null;
String querystr = "select * from [nt:resource]";
int blobsQueried = 0;
long totalSize = 0;
try {
session = repository.login();
QueryManager queryManager = session.getWorkspace().getQueryManager();
Query query = queryManager.createQuery(querystr, Query.JCR_SQL2);
log.info("Run Query = " + querystr);
QueryResult result = query.execute();
NodeIterator nitr = result.getNodes();
int i=0;
while(nitr.hasNext()) {
Node node = nitr.nextNode();
blobsQueried++;
log.debug("Download Blob from Node "+node.getIdentifier()+" path="+node.getPath());
Property property = node.getProperty("jcr:data");
Binary binary = null;
InputStream stream = null;
byte[] blobData;
try {
binary = property.getBinary();
stream = binary.getStream();
blobData = IOUtils.toByteArray(stream);
} finally {
if (stream != null) {
stream.close();
}
if (binary != null) {
binary.dispose();
}
}
int size = blobData.length;
log.info("Blob "+i+" is size "+size);
totalSize+=size;
}
} catch (LoginException e) {
throw new RuntimeException("Could not log into repository", e);
} catch (RepositoryException e) {
throw new RuntimeException("Could not perform operation over the repository", e);
} catch (Exception e) {
throw new RuntimeException("Encountered exception while perform operation over the repository",e);
} finally {
if (session != null) {
session.logout();
}
}
return "Total Rows Returned = " + blobsQueried + " total size = "+totalSize;
}
{code}