R. Rahul
R. Rahul

Reputation: 1186

Hibernate performance and memory leakage issues under profiler

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.

Upvotes: 2

Views: 2468

Answers (2)

Thomas
Thomas

Reputation: 88747

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?

Upvotes: 0

duffymo
duffymo

Reputation: 308988

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.

Upvotes: 3

Related Questions