OutOfMemoryException occurs after loading FileBasedProject

OutOfMemoryException occurs after loading FileBasedPorject.
Here is sample code to reproduce problem.

string[] files = Directory.GetFiles(@"Z:\projects", "*.sdlproj", SearchOption.AllDirectories);
foreach (string file in files)
{
  try
  {
    FileBasedProject project = new FileBasedProject(file);
    Console.WriteLine(project.GetProjectInfo().Name);
   }
   catch (Exception ex)
  {
  Console.WriteLine(ex.ToString());
  }
}


There are many Trados projects(more than 200) in Z:\projects. When loading project one by one and get information from FileBasedProject, memory usage is increased.
Then OutOfMemoryException occurs.
Can we release memory of FileBasedProject to prevent Exception ? How to clear memory of FileBasedProject object?
I use Trados2017 Pro.

Best regards,
Masayuki

Parents Reply
  • Hi, Jesse
    Thanks for your information.
    I tried to use AppDomain in order to prevent memory problem, then it works fine. OutOfMemoryException doesn't occur.


    e.g.
    string[] files = Directory.GetFiles(@"Z:\projects", "*.sdlproj", SearchOption.AllDirectories);
    foreach (string file in files)
    {
    AppDomain ad = AppDomain.CreateDomain("NewDomain");
    var workerType = typeof(Worker);
    Worker remoteWorker = (Worker)ad.CreateInstanceAndUnwrap(
    workerType.Assembly.FullName,
    workerType.FullName);
    remoteWorker.ProcessFile(file);
    AppDomain.Unload(ad);
    }


    Worker class
    public class Worker : MarshalByRefObject
    {
    public void ProcessFile(string projectPath)
    {
    try
    {
    FileBasedProject project = new FileBasedProject(projectPath);
    Console.WriteLine(project.GetProjectInfo().Name);
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.ToString());
    }
    }
    }
Children