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

4 Replies Latest Replies: 19 Jul 2017 11:15 AM by Jesse Good
  • Hi Masayuki,

    Unfortunately I think this is an unsolved problem.
    There is no way to release the memory using the API and forcing a garbage collect will not help either as all the references are valid.

    You can read a discussion about it here:
    community.sdl.com/.../3782
  • In reply to Jesse Good:

    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());
    }
    }
    }
  • In reply to Masayuki Iizuka:

    Hi Masayuki,

    Glad you found a solution!
    In my linked question one person said:
    "I also tried loading the above code into a separated AppDomain, and unloading that domain after execution, but that didn't affect garbage collection at all"

    So I though AppDomain wouldn't work, but thanks for reporting that it does!
  • In reply to Masayuki Iizuka:

    Hi Masayuki,

    this seems to resolve OutOfMemoryExceptions for us as well. Thanks for sharing.

Related