Whenever I run the roslyn's "Execute", the memory increase continuously...

Respuesta propuesta Whenever I run the roslyn's "Execute", the memory increase continuously...

  • miércoles, 04 de abril de 2012 1:17
     
     

    Even though my English is not good as a foreigner, I will ask to seek the way to solve the problem.

    Problem. 1.

    Whenever I run the roslyn's "Execute", the memory increase continuously...

    this program come to halt the program finally.(when...over than 10000th click of button1 )

    what can I do not to halt the program.

    my code on program is like the below.

    //---------------------------------
    using Roslyn.Compilers;
    using Roslyn.Scripting.CSharp;
    using Roslyn.Scripting;

            private void button1_Click(object sender, EventArgs e)
            {
                var engine = new ScriptEngine(new[]
                                                {
                                                    "System",
                                                 this.GetType().Assembly.Location
                                                });

                var session = Session.Create(this);
                //------------------------------------------------------

              
                engine.Execute("int a = 1;" session);
            }

Todas las respuestas

  • miércoles, 04 de abril de 2012 9:52
     
     

    When generating code for a ScriptEngine, Roslyn will try to create collectible assemblies, that don't cause memory leaks, if used correctly.

    But there are some cases where it will use normal assembly, which means you will get a memory leak unless you use separate AppDomains. And using Session is currently among those cases. The Roslyn team is aware of this problem, so it may be fixed in the next release.

    For more information, see the thread "Still need separate AppDomains for dynamic compilation?"

    • Marcado como respuesta Delight72 jueves, 05 de abril de 2012 4:54
    • Desmarcado como respuesta Delight72 jueves, 05 de abril de 2012 5:03
    • Marcado como respuesta Delight72 jueves, 05 de abril de 2012 5:06
    • Desmarcado como respuesta Delight72 jueves, 05 de abril de 2012 6:58
    •  
  • jueves, 05 de abril de 2012 6:58
     
     

    thank you for your kind reply.^^

    I wrote the code again like the below, which didn't use the Session as what you said.

    ---------------------------------------------------------------------------

            private void button1_Click(object sender, EventArgs e)
            {
                GC.Collect();

                    var engine = new ScriptEngine();
                    engine.Execute("using System; int a=1;");

            }

    ------------------------------------------------------------------------

    but, the memory usage is still increasing, continuously .

    I already used the Roslyne in my project. --;

    can I get the sample code which is using the separate Appdomains to avoid the memory leak as what you said? or other way....

    or should I give up to use the Roslyne?






    • Editado Delight72 jueves, 05 de abril de 2012 7:00
    • Editado Delight72 jueves, 05 de abril de 2012 7:02
    • Editado Delight72 jueves, 05 de abril de 2012 7:21
    • Editado Delight72 jueves, 05 de abril de 2012 7:22
    • Editado Delight72 jueves, 05 de abril de 2012 11:54
    •  
  • sábado, 07 de abril de 2012 1:04
    Propietario
     
     

    Hi Delight72 - I tried to reproduce the issue on my machine with the two code examples you provided above. I am able to see the memory usage increasing in the 1st code example above where the code uses sessions - but I am seeing a flat memory trend for the 2nd code example above that doesn't use sessions (see below perf charts captured using process explorer (procexp.exe)). Are you sure you are seeing the memory usage increasing even in the 2nd case?

    With and Without Sessions

    Thanks!


    Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team

  • lunes, 09 de abril de 2012 1:17
     
     

    Thank you for your trial to solve the problem...^^

    I tried it again , when I read your reply.

    but, I get the same memory increasing results on my PC.

    (I used the Timer to speed up in my sample project like the below code. if the codes are long in the script, you can get the result more quickly. of course, the results by the manual work was same )

    the below picture was captured when I tested it. (with procexp.exe..)

    -----------------------------------------------------------------------------------------

    after 70 minutes, the memory usage arrived at about the 90 M bytes.

    --------------------------------------------------------------------------------------

    the full code for this is like the below.

    //--------------------------------------------------------------------------------------

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;
    //---------------------------------
    using Roslyn.Compilers;
    using Roslyn.Scripting.CSharp;
    using Roslyn.Scripting;
    //-------------------------------------------------------

    namespace WindowsFormsApplication7
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                GC.Collect();

                var engine = new ScriptEngine();
                engine.Execute("using System; int a=1;");

             }


            private void timer1_Tick(object sender, EventArgs e)
            {
                button1_Click(null, null);        //tiemr interval is 100 ms.      Timer's property of "Enabled" is true.
            }
        }
    }

    //--------------------------------------------------------------------------------------

    My circumstance for the coding is like the below.

    //--------------------------------------------------------------------------------------

    1. visual studio professional 2010, which was installed with ServicePack 1. I bought it about 3 months ago.

    2. Windows 7, which was installed wiht SP1.

    3. CPU: intel i7-2600, Ram: 4G,

    4. Roslyn Version: Roslyn was released at 10/19/2011.

    5. My program is running for 24 hours, and then memory leak is very important. --;

















    • Editado Delight72 lunes, 09 de abril de 2012 1:28
    • Editado Delight72 lunes, 09 de abril de 2012 2:01
    • Editado Delight72 lunes, 09 de abril de 2012 2:03
    • Editado Delight72 lunes, 09 de abril de 2012 2:08
    • Editado Delight72 lunes, 09 de abril de 2012 2:10
    • Editado Delight72 lunes, 09 de abril de 2012 2:20
    • Editado Delight72 lunes, 09 de abril de 2012 2:25
    • Editado Delight72 lunes, 09 de abril de 2012 4:32
    • Editado Delight72 lunes, 09 de abril de 2012 4:56
    • Editado Delight72 lunes, 09 de abril de 2012 4:58
    • Editado Delight72 lunes, 09 de abril de 2012 5:19
    • Editado Delight72 lunes, 09 de abril de 2012 5:20
    • Editado Delight72 lunes, 09 de abril de 2012 5:23
    • Editado Delight72 lunes, 09 de abril de 2012 5:24
    • Editado Delight72 lunes, 09 de abril de 2012 5:25
    • Editado Delight72 lunes, 09 de abril de 2012 5:26
    • Editado Delight72 lunes, 09 de abril de 2012 9:43
    • Editado Delight72 lunes, 16 de abril de 2012 0:00
    •  
  • viernes, 13 de abril de 2012 0:18
     
     

    Maybe, I should give up to use the Roslyn, because of the memory leak and no answer to solve this problem from MS.... --;(this exhausts the day to develop my project...) --; I must overcom this circumstance...

    Let me know how to use the other method for C# or VB script in C#, please. of course, without memoryleak...

    I wonder how the other people uses the script in c#....

    we'll thank you, if you give the helpful information...

    ------------------


    • Editado Delight72 viernes, 13 de abril de 2012 0:29
    •  
  • viernes, 13 de abril de 2012 2:42
    Propietario
     
     

    Thanks much for the updated repro Delight72 and sorry for the delayed response. I am able to reproduce the issue consistently with this updated repro and I can see the memory increasing (see below image). I have logged a bug for this problem internally. Unfortunately, I am not aware of any workarounds for this issue at the moment - I will ask around if to see if I can find one for you and post the same here.

    Memory Trend

    Thanks much for reporting!


    Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team

  • viernes, 13 de abril de 2012 8:28
     
     

    thank you!  I'll look forward to your reply until April/30/2012....  --;


    • Editado Delight72 viernes, 13 de abril de 2012 8:33
    •  
  • viernes, 29 de junio de 2012 19:44
     
     

    Hi svick,

    I got the same problem when I am trying to use Roslyn. I just want to check if you get any solution towards this problem. Thank you!

  • martes, 03 de julio de 2012 22:15
    Propietario
     
     Respuesta propuesta

    Hi, all.  We are not doing anything yet to tune this problem, but we are well aware of it.  Fundamentally, what is happening is every time we execute code we compile it into an assembly, so the code for all definitions is always around.  We know for long-running and more advanced applications, we'll need to give hosts some control over this, but we have not designed for that yet. 

    I call it advanced because, while we may provide guidance and examples, hosts will need to decide the granularity of code and when to dispose of these assemblies and which Sessions are using which assemblies for code.  We may not be able to provide a general policy that we implement without having the host own the maintenance.

    As I said, we understand the problem, but need to design the best and easiest way for consumers.

    Bill

    • Propuesto como respuesta billchi_msOwner lunes, 09 de julio de 2012 17:50
    •