1
$\begingroup$

I am using Mathematica from .NET (C#) to compute the result based on some input, following is the code snippet of C#

 using (var mathKernel = new MathKernel())
    {                     
        mathKernel.Compute("PDF[NormalDistribution[-5, 3], x]");
        if (mathKernel.Result != null)
        {
            var response = mathKernel.Result.ToString();                        
        }
    }

above code is called after every minute, upon calling a process named "MathKernel.exe" is created every time, occupy approx. 100 MB of RAM and it does not exit after execution of above code.

MathKerne.exe In Task Manager

MathKernel instance is created in using block which is supposed to dispose after end of closing bracket.

Is there something which I am missing?

$\endgroup$
2
  • 2
    $\begingroup$ I can't comment on the .NET specific aspects, but generally, when using Mathematica through a MathLink/WSTP connection, it is preferable to re-use a single kernel instead of starting a new one for each computation. When you are done, you need to close the link to the kernel. How this is done with .NET I do not know, but in case you didn't check the docs yet, you should. Look in SystemFiles/Links/NETLink/Documentation. $\endgroup$
    – Szabolcs
    May 31, 2022 at 10:37
  • $\begingroup$ Welcome to the Mathematica Stack Exchange. Perhaps you can find some wisdom on this page regarding Dispose(). $\endgroup$
    – Syed
    May 31, 2022 at 16:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.