2

I have profiled my J2EE web application using jprofiler. I found there is huge memory leak by looking at vm telemetry graph and recorded object. Using heap walker i conclude that there is a lot of memory leakage because of hibernate criteria, query.list, template.find, over-redid hashCode and equals method and in some of custom request processor. The thing that i am not able to understand is how there could be memory leak.

I checked a lot over google and its understandable that criteria is slower than HQL and obviously than SQL but memory leakage is quite interesting. Is there any chances of memory leak?

Under recorded object screen hashmap objects increased to nearly 100% and memory leakage graph sleeks upward.

I am also showing you my hashcode and equals methol, please have a look:

public boolean equals(Object other) {
    if ( !(other instanceof Associate) ) return false;
    Associate castOther = (Associate) other;
    return new EqualsBuilder()
        .append(this.getAssociateId(), castOther.getAssociateId())
        .isEquals();
}

public int hashCode() {
    return new HashCodeBuilder()
        .append(getAssociateId())
        .toHashCode();
}

Thanks a lot.

R. Rahul
  • 1,166
  • 3
  • 16
  • 40

2 Answers2

3

The EqualsBuilder uses reflection, which can have an impact on perm gen space.

Why rely on those? Why not just write them yourself? If you use IntelliJ, it'll generate methods that work perfectly without refection. Follow Joshua Bloch's recipe and you'll have one less dependency, too.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • Eclipse also generates quite usable implementations of `equals`and `hashCode` :) – Thomas Apr 26 '11 at 09:45
  • @ duffymo, thanks i read the topic and yes i found EqualsBuider has some performance issue. Do you have any idea about hibernate list, find and criteria. – R. Rahul Apr 26 '11 at 10:14
0

Well, you create a new object on every call to equals or hashCode. This might result in higher memory consumption if the GC doesn't run or collect those objects. Do you have memory problems because of this?

Thomas
  • 87,414
  • 12
  • 119
  • 157
  • no i don't think so, memory leakage is diferent from memory consumption. If your application has memory leakage issue then it means you can't free the memory even after GC did its job. Its because of some references that left in some used objects that restrict GC to do its job. – R. Rahul Apr 26 '11 at 10:19
  • @Kuri That's true. However, I'm not quite sure whether the OP really found a memory leak (unused objects that are still referenced somehow and thus cannot be collected) or just high memory consumption. – Thomas Apr 26 '11 at 10:38
  • i am also not that much sure but its written that if vm telemetry graph is moving upward then it means there is a memory leakage. As even if you call GC its not sure GC perform its job. Might that object be remain in memory and some point later it was freed. – R. Rahul Apr 26 '11 at 10:55
  • But the new object is in method scope and should be eligible for GC every time the code exits equals and hashCode. The item that's return is the product of the chained calls from the fluent interface, not the new object itself. That would be a serious problem, indeed. – duffymo Apr 26 '11 at 11:56