Whenever I run the roslyn's "Execute", the memory increase continuously...
-
Mittwoch, 4. April 2012 01: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);
}
Alle Antworten
-
Mittwoch, 4. April 2012 09: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?"
-
Donnerstag, 5. April 2012 06: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?
-
Samstag, 7. April 2012 01:04Besitzer
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?
Thanks!
Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team
-
Montag, 9. April 2012 01: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. --;
- Bearbeitet Delight72 Montag, 9. April 2012 01:28
- Bearbeitet Delight72 Montag, 9. April 2012 02:01
- Bearbeitet Delight72 Montag, 9. April 2012 02:03
- Bearbeitet Delight72 Montag, 9. April 2012 02:08
- Bearbeitet Delight72 Montag, 9. April 2012 02:10
- Bearbeitet Delight72 Montag, 9. April 2012 02:20
- Bearbeitet Delight72 Montag, 9. April 2012 02:25
- Bearbeitet Delight72 Montag, 9. April 2012 04:32
- Bearbeitet Delight72 Montag, 9. April 2012 04:56
- Bearbeitet Delight72 Montag, 9. April 2012 04:58
- Bearbeitet Delight72 Montag, 9. April 2012 05:19
- Bearbeitet Delight72 Montag, 9. April 2012 05:20
- Bearbeitet Delight72 Montag, 9. April 2012 05:23
- Bearbeitet Delight72 Montag, 9. April 2012 05:24
- Bearbeitet Delight72 Montag, 9. April 2012 05:25
- Bearbeitet Delight72 Montag, 9. April 2012 05:26
- Bearbeitet Delight72 Montag, 9. April 2012 09:43
- Bearbeitet Delight72 Montag, 16. April 2012 00:00
-
Freitag, 13. April 2012 00: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...
------------------
- Bearbeitet Delight72 Freitag, 13. April 2012 00:29
-
Freitag, 13. April 2012 02:42Besitzer
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.
Thanks much for reporting!
Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team
-
Freitag, 13. April 2012 08:28
thank you! I'll look forward to your reply until April/30/2012.... --;
- Bearbeitet Delight72 Freitag, 13. April 2012 08:33
-
Freitag, 29. Juni 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!
-
Dienstag, 3. Juli 2012 22:15Besitzer
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
- Als Antwort vorgeschlagen billchi_msOwner Montag, 9. Juli 2012 17:50

