Taritsyn/JavaScriptEngineSwitcher

Out of Memory Error

yawarkhan15 opened this issue · 9 comments

Hi
I am using JavascriptEngineSwitcher with ChakraCore in wpf application, to exceute the javascript file and get the output from the file.
Below details
JavaScriptEngineSwitcher.Chakra : Version 3.7.1
JavaScriptEngineSwitcher.Core : Version 3.3

But some machines i am getting Out of memory Execptions.
Error Occurred at Current Domain:Out of memory.: at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.<>c__DisplayClass33_0.<InnerGetVariableValue>b__0() at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.ScriptTaskWithResult1.Run()
--- End of stack trace from previous location where exception was thrown ---
at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.Invoke[T](Func1 func)## 2021-11-17 10:04:19,149 [20] ERROR Sample|ScriptTaskWithResult1|Run| Exception : Rule Engine Error:Out of memory.: at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.<>c__DisplayClass33_0.b__0()
at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.ScriptTaskWithResult1.Run() --- End of stack trace from previous location where exception was thrown --- at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.Invoke[T](Func1 func)
at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.InnerGetVariableValue(String variableName)
at JavaScriptEngineSwitcher.Core.JsEngineBase.GetVariableValue(String variableName)
at Sample.UI.Utilities.ChakraCoreScriptEngine.d__24.MoveNext()##`

Can u please help me with this.

Hello, Yawar!

This error means that JavaScript engine ran out of memory. Much depends on JavaScript code being executed or how you use the engine.

How many instances of the ChakraCoreJsEngine class do you create? Do you use an using statements when creating instances the ChakraCoreJsEngine class or the Dispose method to destroy them?

Hi @Taritsyn

I am using the 'using' statement and disposing the engine when process is done. I am using wpf in VSTO application so for ever new document I am trying to create a new instance of the engine and after the javascript gets executed it's getting disposed, I even tried to open a single instance it starts the execution but with in few seconds it throws out of memory exception.

I am not able to understand y it's working in some machine and not in other.

Which of the exceptions is thrown: JsRuntimeException or JsEngineLoadException?

I am not able to understand y it's working in some machine and not in other.

It depends on several factors: available amount of RAM, bit depth and version of operating system.

I recommend that you try creating an instance of engine with a fixed stack size:

var engine = new ChakraCoreJsEngine(new ChakraCoreSettings
{
	MaxStackSize = 1007616
});

If recommended stack size is not enough, then you can try increasing it 1.5 or 2 times.

I also recommend updating the JavaScriptEngineSwitcher.ChakraCore module to the latest version.

I even tried to increase the MaxStackSize as you have suggested but i am still getting.
I am getting JsRuntimeException.
Below is the Exception Object { "ClassName": "JavaScriptEngineSwitcher.ChakraCore.JsRt.JsEngineException", "Message": "Out of memory.", "Data": null, "InnerException": null, "HelpURL": null, "StackTraceString": " at JavaScriptEngineSwitcher.ChakraCore.JsRt.JsErrorHelpers.ThrowIfError(JsErrorCode errorCode)", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": "8\nThrowIfError\nJavaScriptEngineSwitcher.ChakraCore, Version=3.7.1.0, Culture=neutral, PublicKeyToken=c608b2a8cc9e4472\nJavaScriptEngineSwitcher.ChakraCore.JsRt.JsErrorHelpers\nVoid ThrowIfError(JavaScriptEngineSwitcher.ChakraCore.JsRt.JsErrorCode)", "HResult": -2146233088, "Source": "JavaScriptEngineSwitcher.ChakraCore", "WatsonBuckets": null, "ErrorCode": 131073 }

"ClassName": "JavaScriptEngineSwitcher.ChakraCore.JsRt.JsEngineException"

This is definitely not an JsRuntimeException exception. It looks like you don't have enough memory even to create an instance of engine. Do you use a MemoryLimit configuration property somewhere?

Try an experiment: replace the JavaScriptEngineSwitcher.ChakraCore by the JavaScriptEngineSwitcher.V8 module.

Hi as per your suggestion i tried to use the V8 Module but i am getting error this.progressFn is not function.
While same is executing with Charka Core. Do V8 needs any additional settings.

Hello, Yawar!

Is the progressFn function added to engine by using the EmbedHostObject method? Is the progressFn function implemented as an method of interface? Is the EmbedHostObject method with the progressFn item name called on instance of engine once or several times?

Is the type of embedded object public and non-nested?