-->
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.  [ 13 posts ] 
Author Message
 Post subject: Possible Memory Leak with SqlString
PostPosted: Wed Feb 08, 2006 8:11 am 
Regular
Regular

Joined: Tue May 31, 2005 9:55 am
Posts: 67
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

1.0.1.0

Name and version of the database you are using:

MS Sql Server 2000


I deployed an application that makes heavy use of dynamic HQL Query String and their execution. I noticed the application was growing in memory quite rapdily so I ran a memory profiler on it. The profiler showed that the SqlString instance count was growing uncontrollably. Does NHibernate try and cache these HQL statements?

Should I create a JIRA issue for this?

thanks,
craig


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 9:46 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, please create a JIRA issue. An example exhibiting the problem would be nice.


Top
 Profile  
 
 Post subject: SqlString
PostPosted: Thu Mar 09, 2006 10:15 am 
Newbie

Joined: Thu Mar 09, 2006 10:09 am
Posts: 5
Hello,

I'm having the same problem. We didn't notice it until we started doing load tests, and now we're running out of time with the project deadline. I look in JIRA but I cannot see that this bug was reported.
We're using the same NHibernate version/database configuration.
Please help!

Peter.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 5:27 am 
Newbie

Joined: Thu Mar 09, 2006 10:09 am
Posts: 5
I was a problem on our side after all...
Some of us were using Query API with query strings created via concatenation, instead of using parameters, so the number of cached queries was growing uncontrollably.

regards,
P.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 3:58 pm 
Regular
Regular

Joined: Tue May 31, 2005 9:55 am
Posts: 67
Sorry for the late reply.

I created the issue for this

http://jira.nhibernate.org/browse/NH-559


I am also creating query strings through concatention and not using parameters. Is there a way to limit the number of cached queries?

thanks,
craig


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 4:34 pm 
Newbie

Joined: Thu Mar 09, 2006 10:09 am
Posts: 5
Hi,

I wouldn't say this is a bug. Basically, you should use ISession.Find() function if you don't want to use paramertised queries. Query caching should be OK, beacuse in normal Query use (without concatenation) total number of unique queries in one application shouldn't grow unlimitedly.

P.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 10:42 pm 
Regular
Regular

Joined: Tue May 31, 2005 9:55 am
Posts: 67
I agree with you that the number of queries is usually limited?

Does ISession.Find() cache the queries too? I use ISession.CreateQuery so I can set SetFirstResult and SetMaxResults?

thanks,
craig


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 9:35 am 
Regular
Regular

Joined: Tue May 31, 2005 9:55 am
Posts: 67
After doing some tests, it appears that ISession.Find suffers from the same memory consumpltion problem. Is using parameterized queries the only way to prevent this memory consumption?

thanks,
craig


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 9:40 am 
Newbie

Joined: Thu Mar 09, 2006 10:09 am
Posts: 5
Hi,

We had no more memory leaks after we changed the code to use Find().

P.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 10:26 am 
Regular
Regular

Joined: Tue May 31, 2005 9:55 am
Posts: 67
Even when using concatentated queries? Hmm, I wrote a simple unit test that performed 1000 Session.Find with different queries. I used GC.GetTotalMemory to get the bytes before and after the queries and it seemd to suggest significat memory consumption. I made sure I did a GC.Collect before getting the results.

My problem with parameterized queries is that I want to use the IN clause with a composite identifier and I don't think that is supported.

craig


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 10:29 am 
Newbie

Joined: Thu Mar 09, 2006 10:09 am
Posts: 5
You closed the session, I guess?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 10:47 am 
Regular
Regular

Joined: Tue May 31, 2005 9:55 am
Posts: 67
I sure did.

Code:
GC.Collect();

Simple simple = CreateAndSaveSimple();
   
long bytesBefore = GC.GetTotalMemory(true);

for (int i = 0; i < 1000; ++i)
{
   using( ISession s1 = OpenSession() )
   {
      IList results = s1.Find("select s from Simple s where s.id = " + i);

      GC.Collect();

      long bytesAfter = GC.GetTotalMemory(true);
      long memoryUsed = bytesAfter - bytesBefore;

      Assert.IsTrue(memoryUsed <= 30000, "Memory used was " + memoryUsed + " bytes");   


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 11:24 am 
Regular
Regular

Joined: Tue May 31, 2005 9:55 am
Posts: 67
sergey,

Is it true that ISession.Find and ISession.CreateQuery will accumulate the distinct query string idefinitely?

thanks,
craig


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 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.