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.  [ 2 posts ] 
Author Message
 Post subject: OutOfMemoryException when using BLOBs
PostPosted: Mon Mar 15, 2010 10:49 am 
Newbie

Joined: Mon Mar 15, 2010 10:29 am
Posts: 2
Hi,

im accessing a database table with NHibernate (Version 2.1.2). The table contains one binary column (and some other string columns). My data object uses a byte array to store this column.
It works fine to insert and to read records of this table with NHibernate.

I insert at some files with defined file sizes from 1 Byte to 25 MB, in total 280 MB of Data in 55 files. This procedure is repeated 50 times. But after about 20 to 25 times there is a OutofMemoryException.

Do you have any idea what is going wrong or what i can do to solve this problem?

Here is my source code:

Code:
void IDocbaseEntryRepository.Add(DocbaseEntry docbaseEntry)
        {

            using (ISession session = NHibernateHelper.OpenSession())

            using (ITransaction transaction = session.BeginTransaction())
            {
                try
                {
                    session.Save(docbaseEntry);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    aLogger.ErrorException("Hibernate-Error: ", ex);
                    transaction.Rollback();
                    throw ex;
                }
                finally
                {
                    session.Clear();
                    session.Close();
                }
            }
        }


Top
 Profile  
 
 Post subject: Re: OutOfMemoryException when using BLOBs
PostPosted: Wed Mar 17, 2010 4:02 am 
Newbie

Joined: Mon Mar 15, 2010 10:29 am
Posts: 2
Hi,

it seems as if I've found a solution to the problem described above. There was no problem using BLOBs. It was a problem in using the SessionFactory.
After a cycle of inserting about 50 files into the database (and afterwards reading them) i have reset the SessionFactory (aSessionFactory = null) and created a new one.
But the Garbage Collector does not clean the discarded SessionFactory until you invoke aSessionFactory.Dispose();
So the solution is to invoke aSessionFactory.Dispose(); or not trying to reset a SessionFactory and only use one SessionFactory object.

I hope i could help other people not to run in this situation too.


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