BlazeDS 4 is used to communicate with Flex4.6. When flex client invokes a remote call on blazeds server, server returns an arrayList containing POJOs. Assuming each POJO mem size is 12 bytes, I am expecting the arrayList size to be 12*number of elements. However, I find that somewhere in blazeds, it is compounded multiple times. Assuming I add 200000 POJOs into the array list, I am expecting its size to be ~2MB. But, I could see through profilers, that JVM shoots up N times of original size and the same N times mem is being transfered to the flex browser application also. Below listed is a sample code that demonstrates the problem, with jmap profiler captures. I would be happy to provide the flex code also if needed.
List list = new ArrayList();
for(i=0;i<200000;i++)
{ SampleClass sampleClassObj = new SampleClass();
sampleClassObj.setId(1);
sampleClassObj.setAge(20);
list.add(sampleClassObj);
}
return list;
And the SampleClass class definition is as follows
public class SampleClass
{
long id;
int age;
// getters and setters for each variables
}
Memory is profiled in jmap.exe which resides in jdk path. The intitail memory in JVM before recieving a request from client was ~50MB. The output from jmap before request from client.
num #instances #bytes class name
1 63135 8497488 constMethodKlass
2 65671 7858440 [C
3 91344 5217976 symbolKlass
.
.
total 658429 50097416 //initial memory in JVM
The output from jmap after processing request.
num #instances #bytes class name
1 11402 20225512 [B
2 200000 1948809 SampleClass //as expected to be ~2MB
3 62734 8451040 constMethodKlass
.
.
total 1175132 93938272 //consumed memory in JVM which is not garbage collected.
Strange enough, when I try to invoke the same method from Flex repeatedly, the JVM memory does not correspondingly increase. It is only the first time multifold increase that is seen in JVM. However, the flex client application memory keeps increasing for every call.
I even tried running the same on YourKit profiler and tried invoking GC multiple times in vain.
Can someone please make me understand what is going on within blazeds.