C# AM standalone program memory release

 
  • I made a standalone program that collect all of DBelement from a project
    code is work well, but it can't release memories and is killed from windows
    Code is Below, i copied parts of them

    Do you have any ides or ways to release memories.



    #1 code

                   TypeFilter filter = new TypeFilter(DbElementTypeInstance.SITE);
                   DbElement world = MDB.CurrentMDB.GetFirstWorld(Aveva.Pdms.Database.DbType.Design);
                   DBElementCollection collection = new DBElementCollection(world, filter);
                   filter = null;
                   world = null;

                   long mem = 0;
                   DbElement ele = null;
                   DBElementEnumerator iter = (DBElementEnumerator)collection.GetEnumerator();
                   while (iter.MoveNext())
                   {
                       mem = GC.GetTotalMemory(true);
                       Console.WriteLine("memory : {0}", mem);

                       ele = (DbElement)iter.Current;
                       if (ele != null && ele.IsValid)
                       {
                          Get_Element_From_Site(ele, atts, adodb, tablename);  [COLOR="#FF0000"] // --> call #2 code [/COLOR]
                       }
                       ele = null;
                   }
                   Console.WriteLine("GetNameTable was finished");


    #2 code
               DBElementCollection collection = new DBElementCollection(aSite, filter);  [COLOR="#FF0000"] // --> I think this collection variable doesn't release memory  [/COLOR]
               collection.IncludeRoot = true;

               List
  • This you done in Class Library ??

    What is the Version Of Visual Studio??
  • it is standalone program and my VS version is 2010
  • Can you show us the Exception stack trace? This is quite hard to diagnose without having some information about which line (and call path) exactly leads to the OutOfMemoryException.
  • It's not an Exception, but I'm constantly checking for a lack of memory, and it's usually not a memory release when checking COG.