You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using typescriptServices.js file, for transpiling typescript code to javascript, it appears to be a memory leak. The size of the library is ~6MB
After each call to CallGlobalFunction, the memory goes up by 30MB, and never goes down
public sealed class ScriptCompiler
{
private readonly ScriptEngine jSEngine;
public ScriptCompiler()
{
jSEngine = new ScriptEngine();
var compilerSourceStream = Assembly.GetAssembly(this.GetType())
.GetManifestResourceStream("typescriptServices.js");
var compilerSource = ReadStream(compilerSourceStream);
jSEngine.Evaluate(new StringScriptSource(compilerSource));
var bootstrapSourceStream = Assembly.GetAssembly(this.GetType())
.GetManifestResourceStream("nTypescriptBootstrap.js");
var bootstrapSource = ReadStream(bootstrapSourceStream);
jSEngine.Evaluate(new StringScriptSource(bootstrapSource));
}
private string ReadStream(Stream stream)
{
var value = string.Empty;
using (stream)
{
using (var sourceReader = new StreamReader(stream))
{
value = sourceReader.ReadToEnd();
}
}
return value;
}
public string Compile(string source)
{
Ensure.NotNullEmpty(source, "ScriptCompiler.Source is empty");
try
{
var transpileResult = jSEngine.CallGlobalFunction("tsTranspile", source);
var outputCode = jSEngine.CallGlobalFunction<string>("getTranspileResultCode", transpileResult);
//Need to call GC.Collect here, otherwise memory goes up by 30MB after each call
GC.Collect();
return outputCode;
}
catch (Exception ex)
{
return "";
}
}
}
The text was updated successfully, but these errors were encountered:
When using typescriptServices.js file, for transpiling typescript code to javascript, it appears to be a memory leak. The size of the library is ~6MB
After each call to CallGlobalFunction, the memory goes up by 30MB, and never goes down
The text was updated successfully, but these errors were encountered: