hibernate中@Entity的对象对应的表字段非常多的情况

小弟在项目中遇到了内存瓶颈,服务器内存总是溢出,我在后面会列出dump文件的内容,我在猜想hibernate将表对象化成@Entity的对象,如果这个对象的成员变量很多,换言之表的字段很多(200左右),如果调用类似save,query的方法是不是很占用内存?还有几个疑问也请大家帮着解释一下,我只是在猜想:

1java中对象的成员变量越多,在new的时候是否会占更多的内存?

2hibernate中在SQLQuery.list()方法和类似findByExample的方法后是否需要调用flush和clear,有些地方说需要调用,否则会有内存的问题,我不确定。

dump:

1.

LeakSizeTotalSizeSizeAnalysisNameAddress

97138970397139651724Responsiblefor971,396,517bytes(57.8%)ofJavaheaporg/apache/commons/collections/SequencedHashMap$Entry0x82b2c5e8

1,258,104,359(74.86%)[40]1java/util/HashMap0x7f53ffc8

1,258,104,319(74.86%)[64]2arrayof[Ljava/util/HashMap$Entry;0x83c2bc88

1,258,104,184(74.86%)[24]2java/util/HashMap$Entry0x83c2bd40

1,258,104,160(74.86%)[30]2org/springframework/orm/hibernate3/SessionHolder0x83c2be48

1,258,104,100(74.86%)[28]2java/util/Collections$SynchronizedMap0x83c2bed8

1,258,104,072(74.86%)[40]1java/util/HashMap0x83c2bf48

1,258,104,032(74.86%)[8]1arrayof[Ljava/util/HashMap$Entry;0x83c2bf70

1,258,104,024(74.86%)[24]2java/util/HashMap$Entry0x83c2bf88

1,258,104,000(74.86%)[80]11org/hibernate/impl/SessionImpl0x82b0ee38

1,258,102,913(74.86%)[78]13org/hibernate/engine/StatefulPersistenceContext0x82b0f308

980,349,426(58.33%)[17]2org/hibernate/util/IdentityMap0x82b2c110

980,349,405(58.33%)[24]2org/apache/commons/collections/SequencedHashMap0x82b2c588

971,396,517(57.8%)[24]2org/apache/commons/collections/SequencedHashMap$Entry0x82b2c5e8

971,396,406(57.8%)[24]4org/apache/commons/collections/SequencedHashMap$Entry0x7f619578

87(0%)[24]4org/apache/commons/collections/SequencedHashMap$Entry0xffffffffe5e9b240

2.

LeakSizeTotalSizeSizeAnalysisNameAddress

2777522972777522972097152277,752,297bytes(16.53%)ofJavaheapisusedby220,347instancesofjava/util/HashMap$Entryarrayof[Ljava/util/HashMap$Entry;0xb5cbe268

1,258,104,387(74.86%)[28]3java/lang/ThreadLocal$ThreadLocalMap$Entry0x7ba45208

1,258,104,359(74.86%)[40]1java/util/HashMap0x7f53ffc8

1,258,104,319(74.86%)[64]2arrayof[Ljava/util/HashMap$Entry;0x83c2bc88

1,258,104,184(74.86%)[24]2java/util/HashMap$Entry0x83c2bd40

1,258,104,160(74.86%)[30]2org/springframework/orm/hibernate3/SessionHolder0x83c2be48

1,258,104,100(74.86%)[28]2java/util/Collections$SynchronizedMap0x83c2bed8

1,258,104,072(74.86%)[40]1java/util/HashMap0x83c2bf48

1,258,104,032(74.86%)[8]1arrayof[Ljava/util/HashMap$Entry;0x83c2bf70

1,258,104,024(74.86%)[24]2java/util/HashMap$Entry0x83c2bf88

1,258,104,000(74.86%)[80]11org/hibernate/impl/SessionImpl0x82b0ee38

1,258,102,913(74.86%)[78]13org/hibernate/engine/StatefulPersistenceContext0x82b0f308

980,349,426(58.33%)[17]2org/hibernate/util/IdentityMap0x82b2c110

277,752,337(16.53%)[40]1java/util/HashMap0x82b2c0c0

277,752,297(16.53%)[2,097,152]220,347arrayof[Ljava/util/HashMap$Entry;0xb5cbe268

相关推荐