Out of memmory exception

Posts   
 
    
wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 23-Aug-2005 14:17:52   

Hi Frans

My Webapplication that is using LLBLGen has started to thow Out of memmory exceptions. The traffic to the site has increased in the last few months. The exception now happens every second week or so. The challenge is that it seem that only a reboot fixes the problem.

This is a simple DB Application that uses LBLGen no funny Vista engines.

I am using self servicing. .Net 1.1

The server has 2GB RAM any idea? .Net is suppose to free memmory isn't it?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 24-Aug-2005 10:00:14   

Typically this is caused by keeping entities around in sessions or application objects. You can do that, though if you fetch data into these objects, it won't be removed from memory unless you remove the parent objects: if you keep a customer entity in the session, and you load customer.Orders at one time into that object, the customer.Orders objects aren't removed from memory unless the customer object is removed as well.

Frans Bouma | Lead developer LLBLGen Pro
wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 24-Aug-2005 10:09:20   

Thanks frans, i will have to keep an eye out for those type of things - although i don't think that any objects are being saved in te session or application state.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 24-Aug-2005 10:45:01   

Well, any type if 'cache' keeps the objects around. So keep an eye on that.

Frans Bouma | Lead developer LLBLGen Pro
wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 28-Sep-2005 12:49:51   

Ok - I had this problem again last night at 22:00. rage As you can see it has been a month since my last report.

Another thing is that we have also been experiencing Connection Pool problems where max pool size has been reached. That tells me that the connections aren't being returned to the pool for re-use. I have gotten past this problem by increasing the pool size.- But this might also be causing my memory problems.

My max pool size is now - 1000 frowning And my connectin lifetime is set to - 60

I noticed today that the connection object has a dispose method. What happens to connection objects that gets create in DBUtils.CallRetrievalStoredProcedure ? Who is responsible to call the dispose method of the connection after using it?- Is it the same as the transaction object where you must explicitly call dispose yourself or will the garbage collection sort it out.

        public static bool CallRetrievalStoredProcedure(string storedProcedureToCall, SqlParameter[] parameters, DataSet dataSetToFill, ITransaction transactionToUse)
        {
            SqlCommand command = null;
            string procName = SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.GetNewStoredProcedureName(storedProcedureToCall);
            if(transactionToUse!=null)
            {
                command = new SqlCommand(procName, (SqlConnection)transactionToUse.ConnectionToUse);
                command.Transaction = (SqlTransaction)transactionToUse.PhysicalTransaction;
            }
            else
            {
                command = new SqlCommand(procName, CreateConnection());
            }
            command.CommandType = CommandType.StoredProcedure;
            command.CommandTimeout = _commandTimeOut;

            SqlDataAdapter adapter = new SqlDataAdapter(command);
            for(int i=0;i<parameters.Length;i++)
            {
                command.Parameters.Add(parameters[i]);
            }
            adapter.Fill(dataSetToFill);

            return true;
        }
wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 02-Oct-2005 17:01:23   

Frans you were right! simple_smile

I think i might have found the problem for the connections leaks.

There was some code that was storing a collection in the session. This collection was created and loaded into the session for every new session. The idea behind this was; Fetch this huge lookup table once and store it because it gets used right through the life time of the session.

Now because it was creating this collection for every new session and storing it.. - We were loosing 1 connection object per session...well that is what i think in any case.

I changed it to check if the collection exists before creating it and then storing the collection in the application state for the moment. So the worse case is that i am going to loose 1 connection until i can come up with a better idea.

Another piece of code that i am worried about is the following code that sits in my aspx page:

<%=CurrentClient.ThisCompany.CompanyName%>,<%=CurrentClient.ThisCompany.CompanyNameLong%>

These objects reads from the database - can i leak connections this way? The object ThisCompany wraps an entity.

Can my connection leaks cause my OutOfMemory exceptions? Because i am still chasing this exception and have no idea where to start looking.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 03-Oct-2005 11:50:00   

wayne wrote:

Another piece of code that i am worried about is the following code that sits in my aspx page:

<%=CurrentClient.ThisCompany.CompanyName%>,<%=CurrentClient.ThisCompany.CompanyNameLong%>

These objects reads from the database - can i leak connections this way? The object ThisCompany wraps an entity.

No, it will open a connection and close it again. This connection is normally retrieved from the connection pool

Can my connection leaks cause my OutOfMemory exceptions? Because i am still chasing this exception and have no idea where to start looking.

It's probably due to loading a lot of data in all kinds of objects which are kept in-memory due to a reference somewhere. And this can be just 1 reference which references a single entity, which references collections etc. etc...

Frans Bouma | Lead developer LLBLGen Pro