memory leak, OutOfMemoryError - with testcase
jjakub Mar 21, 2012 4:23 AMon second run of below route I get OutOfMemoryError
final genereated xml file is 50Mb, servicemix is started with -Xmx 2048
in comments I show heap size shown by jvisualvm
general idea is I generate response with 20.000 objects, than I convert it to Document, serialize to xml and send to client
public class MemoryTestRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
TransformMemoryTestRequest transformRequest = new TransformMemoryTestRequest();
getContext().setLazyLoadTypeConverters(true);
from("direct:MemoryTestRoute")
.bean(transformRequest, "transformToSzukajResponse") // before transform heap is 240MB after 260MB
.log("przetranformowal")
.bean(transformRequest, "dbg1") // here in brkp its 260MB
.convertBodyTo(Document.class)
.bean(transformRequest, "dbg2") // here in brkp its 720MB
.bean(transformRequest, "transformDocument")
.unmarshal(getJaxbDataFormat(SzukajResponse.class))
.bean(transformRequest, "debug"); // here in brkp its 740MB, meanwhile it peaked to 1200MB but possibly gc run
}
}
during sending to client memory peaks to 1500 MB, afterwards heapsize is 1000MB and memory is not fried, it dont return to starting point, on next run of the same route I get java.lang.OutOfMemoryError: Java heap space
if I force gc with visualvm before second run heap size falls only to 950 MB
beans.xml:
here helper class to generate 20.000 objects in response and do some debuging
public class TransformMemoryTestRequest {
public Document transformDocument(Document input) {
System.out.println("transformDocument input " + input);
return input;
}
public SzukajResponse transformToSzukajResponse(Object input) {
System.out.println("transformToSzukajResponse input " + input);
SzukajResponse response = new SzukajResponse();
for (int i = 0; i < 20000; i++){
response.add generated object
}
return response;
}
public SzukajResponse debug(SzukajResponse response) {
System.out.println("kontrakty.size " + response.getRezultatWyszukiwania().getKontrakts().size());
return response;
}
public Object dbg1(Object input){
System.out.println("dbg1 " + input);
return input;
}
public Object dbg2(Object input){
System.out.println("dbg2 " + input);
return input;
}
public Object dbg3(Object input){
System.out.println("dbg3 " + input);
return input;
}