Skip to content
This repository was archived by the owner on Oct 29, 2019. It is now read-only.

Critical Memory Leak #7

Open
endeffects opened this issue Sep 13, 2018 · 3 comments
Open

Critical Memory Leak #7

endeffects opened this issue Sep 13, 2018 · 3 comments

Comments

@endeffects
Copy link

endeffects commented Sep 13, 2018

When i try to generate code from compiled templates i'm running into a critical memory leak.
The following code is for demonstration only.

var template = File.ReadAllText("Template.txt");

Parallel.For(0, 1000, (i) =>
{
    var compiledTemplate = engine.CompileTemplate(template);
    var result = compiledTemplate.Process();
});

Btw: All higher level template processing is effected too.

@atifaziz
Copy link
Owner

Can you share more details? Like:

  • What's Template.txt like? What if it's 1GB in size then no surprises!
  • How do you know leaking memory? What tool did you use?
  • Can you share numbers or a picture of the memory leak?
  • What do you define as critical?
  • Did you measure the garbage collection frequency and heaps?
  • Did you try adding a periodic GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced)?

My hunch is that the leak (if any) is coming from the use of Roslyn's C# scripting, which I have heard (from @filipw) is not designed to be used for long-running processes; that is, garbage compiled templates do not get collected. I could be wrong and so it should be confirmed with the Roslyn team/project.

@endeffects
Copy link
Author

Thanks for the fast reply. Well the Template is a simple Class with some Placeholders, nothing special. There is also no Scripting involved which generates additional Code.

For testing i‘ve used the vs 2017 Monitoring Tools and the Taskmanager.

For now i just wrote this simple Stress Tool to check the Performance.

@endeffects
Copy link
Author

endeffects commented Sep 13, 2018

Btw, i saw a similar behavior in the past by using the Microsoft implementation. I was able to fix this by using a singleton for the Engine and by disposing the AppDomain within the SessionHost.

I also tried this with your Library, but the CompiledTemplate Class throws an IndexOutBounceException by re-using it within the loop. Also i‘m not able to dispose the AppDomain by Design.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants