-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate collections memory overhead
PostPosted: Fri Dec 16, 2005 12:32 am 
Beginner
Beginner

Joined: Thu Jan 22, 2004 8:22 pm
Posts: 48
I've been doing some profiling of late and noticed a small issue with one of my application. In this application I end up loading a heirarchy of objects in a parent/child relationship. Any node in teh tree might have children and the children are stored as a List.

The issue comes in that the majority of the nodes are in fact leaf nodes which have no children. On these nodes Hibernate sets a empty list which well enough until you take a look at memory consumption. The empty list consumes over 300 bytes. So in my application were I might have 10,000+ nodes in memory at a time and most are leaf nodes I'm using up 3MB of memory to hold these empty lists.

So anyway I've been tinkering for several days now trying to figure out a way to change things so that a null value is used to represent these list. I tried checking in the setter and when Hibernate provided a empty list I threw it away and just kept the reference null. Unfortunately this triggered Hibernate to do spurious updates which is pretty much what I expected.

I've considered switching to arrays but that would really complicate the code handling updates. I'm now considering a user type but a user type to hande lists seems a little more complicated then the ones I've done so far. I was wondering if anybody had any better ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 12:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Write a UserCollectionType and implement UserType.instantiate() like so:

Code:
   public Object instantiate() {
      return new ArrayList(0);
   }


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 9:12 am 
Beginner
Beginner

Joined: Thu Jan 22, 2004 8:22 pm
Posts: 48
We're currently migrating from 2.1.8 to 3.0 and it looks like your suggestion was for the 3.x series. I'll try this ouot during our current conversion.

I was wondering though. I assumed I'd have to at least check and see if the list would be empty and then either return null for a empty list or return the normal Hibernate persistent list. Will what you showed result in the attribute being set null or in the attribute being set with a empty standard Java ArrayList?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.