Do I need to dispose any LLBL related objects?

Posts   
 
    
imakimak
User
Posts: 62
Joined: 18-Mar-2010
# Posted on: 28-May-2010 18:59:05   

LLBL Pro 2.6, .net 3.5 , Visutal Studio 2008, C#

  1. If I declare an entity collection and use it within a function scope, do I need to call Dispose on this collection before function goes out of scope?

  2. How about if this collection is been used as a class variable.

  3. Are there any LLBL generated object that uses any unmanaged objects inside, where I should call dispose

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-May-2010 06:44:26   
  1. It's not necessary to dispose the collection yourself. objects are disposed when they get out of scope.

  2. The same applies. When the instance of the class goes out of scope the collection variable should be disposed by default.

  3. No as far as I know. It's always wise to enclose some instances between "using" statement, to improve the diposing mechanism, like

using (DataAccessAdapter = new DataAccessAdaper())
{...}
David Elizondo | LLBLGen Support Team
imakimak
User
Posts: 62
Joined: 18-Mar-2010
# Posted on: 31-May-2010 15:37:45   

That’s pretty much what I thought too.

Here is the situation. Our winform application uses LLBL collections heavily and mostly uses these collection objects declared as class variables. Lately QA has start noticing that application memory usage is going up. One of my colleague was tasked to find root cause and he concluded that these collection class instances are causing memory leaks. These object hangup in memory even though winform itslef has been disposed. After that he just updated overridden Dipose method in all the winforms and called dispose method of related collection objects. Since then application memory usage has been found to be normal. Now as a "good"practice, whole team is been asked to always call dispose method of any LLBL related objects that we have as class instance. Some poeple are taking a step further and calling dipose for any LLBL collection that have been declared within a function scope. I asked the reason and they say "just to be on safe side" simple_smile

Based on all this can you think of any scenarios where LLBL collections can cause memory related issues?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 31-May-2010 15:59:06   

It depends on how you are using them.

If entities inside this collection reference another external (doesn't belong to the forum) entity which is living in memeory, these entities will remain in memory till the entity they refer to is disposed.

So try to take care of references which might lead to a big graph hanging around.

imakimak
User
Posts: 62
Joined: 18-Mar-2010
# Posted on: 31-May-2010 16:17:01   

The entities are generated via LLBL Designer based on a SQL server db schema. Some additional fields have been added to few entities via partial classes but we are not referring to any unmananged code or external libraries withing those partial classes.

Any suggestion on how ca I look at this graph?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 31-May-2010 16:25:38   

I'm not speaking about unmanaged code or external libraries.

I ment something like the following:

If you have an Orders Form which hold a collection of Order Entities (_orders). And you have a global variable: Customer Entity (Customer).

If you set link them together as follows:

foreach(var order in _orders)
{
    order.Customer = Customer;
}

Then if you close or dispose the Orders Form, the Order Entities will remain in memory because they are referenced by another Entity which lives outside the boundary of the Form. And this will remain the case unless you dispose the Customer entity.