OutOfMemory exception and Rollback

Posts   
 
    
wvnoort
User
Posts: 96
Joined: 06-Jan-2005
# Posted on: 01-Dec-2005 14:29:05   

Some of code we have build generate sometimes OutOfMemory exceptions. I am now rewriting parts of it, to make it use less memory. Much of the problematic code has the same pattern. In simplified form it is like:


EntityCollection invoices = new EntityCollection(new InvoiceEntityFactory());

try
{
    adapter = DataAccessAdapterFactory.GetDataAdapter( true );


    invoices = GetInvoices(someDate);
            
    adapter.StartTransaction( IsolationLevel.ReadCommitted , "Trans-Invoices" );

    Method1(invoices);
    Method2(invoices);
        ...         

    adapter.Commit();
    return 0;
}
catch
{
    if(adapter != null && adapter.IsTransactionInProgress)
    {
        //draai alle database bewerkingen in de transactie terug
        adapter.Rollback();
    }
    throw;
}
finally
{
    if ( adapter != null )
        adapter.CloseConnection();
}

So here is the question: What happens when Method1 or Method2 raises an OutOfMemory exception? Will the adapter still be able to perform the rollback?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 01-Dec-2005 14:39:32   

Should be OK, as the rollback is just doing ROLLBACK TRANS on the db server.

Could you elaborate a bit what eats up the memory or why you're getting outofmemory exceptions?

Frans Bouma | Lead developer LLBLGen Pro
wvnoort
User
Posts: 96
Joined: 06-Jan-2005
# Posted on: 01-Dec-2005 16:59:05   

The main problem is that a lot of data is fetched. As an example, the function i am now working on fetches about 6800 rows and prefetches 2 additional collections (with a total of 145000 rows and 235000 rows). Furthermore, there can be more threads with similar amounts at the same time.

[Edit] By the way, does anybody know a method to find out how much memory is still available for the current process/thread?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 01-Dec-2005 18:21:44   

wvnoort wrote:

The main problem is that a lot of data is fetched. As an example, the function i am now working on fetches about 6800 rows and prefetches 2 additional collections (with a total of 145000 rows and 235000 rows). Furthermore, there can be more threads with similar amounts at the same time.

That's indeed a lot.

Though a lot of memory is currently wasted on entity field info which should be shared among all instances. I hope to bring down memory usage a lot in v2.0.

In the meantime, try paging, if possible.

[Edit] By the way, does anybody know a method to find out how much memory is still available for the current process/thread?

Have you tried performance monitor? Ok, not from code, but you can examine a lot of counters related to .NET which can give you a clear picture what the memusage is of the current thread/appdomain etc.

Frans Bouma | Lead developer LLBLGen Pro