Freeing Memory for returned Collections

Posts   
 
    
erwin avatar
erwin
User
Posts: 21
Joined: 18-Feb-2005
# Posted on: 16-Aug-2005 12:03:08   

I have a collection of Entity objects. For each of these objects I call GetMulti....() to retrieve a collection of dependent Entities. Is there a way to release Memory occupied by the resulting Collection without freeing the original Entity Object.

Example:

{ ImportMachineCollection imc = new ImportMachineCollection(); imc.GetMulti(null);

foreach(ImportMachine im in imc) { ImportSoftwareSignatureCollection issc = im.GetMultiImportSoftwareSingature(false);

  // ... do some work with issc
  // now im seems to hold a reference to the returned collection, so even if issc gets out of scope, memory is not released.

  // is there a way to release this reference, withouth destroying the im Entity / imc Collection? 
 // In my application, the resulting memory footprint would be more than 2 GB...

}

} // here imc gets out of scope, memory gets freed

pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 16-Aug-2005 20:53:54   

As soon as your foreach closes im goes out of scope and should get garbage collected. Within the foreach you can set im to null. Not sure what this buys you though.

BOb

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 16-Aug-2005 21:14:03   

After ImportSoftwareSignatureCollection issc = im.GetMultiImportSoftwareSingature(false); and processing do im.ImportSoftwareSingature.Clear();

and the references are gone to the issc collection contents. Another option is to create a filter yourself and simply define a new ImportSoftwareSignatureCollection and fetch the data in there, thus without using the fetch of im.

Frans Bouma | Lead developer LLBLGen Pro
erwin avatar
erwin
User
Posts: 21
Joined: 18-Feb-2005
# Posted on: 16-Aug-2005 22:13:44   

pilotboba wrote:

As soon as your foreach closes im goes out of scope and should get garbage collected. Within the foreach you can set im to null. Not sure what this buys you though. BOb

You are right, of course - the problem is that within the foreach memory consumption goes to over 2GB of RAM. Setting im to null is not a solution since the object that im points to is still referenced by the imc collection.

See Otis comment further down

erwin avatar
erwin
User
Posts: 21
Joined: 18-Feb-2005
# Posted on: 16-Aug-2005 22:15:03   

Otis wrote:

After ImportSoftwareSignatureCollection issc = im.GetMultiImportSoftwareSingature(false); and processing do im.ImportSoftwareSingature.Clear();

and the references are gone to the issc collection contents. Another option is to create a filter yourself and simply define a new ImportSoftwareSignatureCollection and fetch the data in there, thus without using the fetch of im.

Thanks! I'll try this out tomorrow.

Erwin

erwin avatar
erwin
User
Posts: 21
Joined: 18-Feb-2005
# Posted on: 17-Aug-2005 17:03:57   

erwin wrote:

Otis wrote:

After ImportSoftwareSignatureCollection issc = im.GetMultiImportSoftwareSingature(false); and processing do im.ImportSoftwareSingature.Clear();

and the references are gone to the issc collection contents. Another option is to create a filter yourself and simply define a new ImportSoftwareSignatureCollection and fetch the data in there, thus without using the fetch of im.

Erwin

Works perfectly, thanks.