I need to be able to at least compile the snippet from the C# code and
then reuse it multiple times. I noticed that the PythonEngine.Execute()
method does something along these lines:
public void Execute(string text) {
Parser p = Parser.fromString(text);
Stmt s = p.parseFileInput();
FrameCode code = OutputGenerator.GenerateSnippet(s, "input",
true);
code.Run(new Frame(_module));
}
If I can somehow hold this FrameCode object and the execute it over and
over on the same module would it help?
Szymon.
Martin Maly wrote:
>Yes, you can precompile the code snippets. For example, the code below doesn't
>'leak'. Depending how dynamic your scripting is, this may not help always, but
>hopefully some:
>
>x = compile("2+2", "<string>", "eval")
>for i in xrange(123456789):
> eval(x)
>
>Martin
>
>-----Original Message-----
>From: Szymon Kobalczyk [mailto:[EMAIL PROTECTED]
>Sent: Friday, November 04, 2005 2:30 PM
>To: Martin Maly; [email protected]
>Subject: Re: [IronPython] Is this memory leak ?
>
>But do you have any workaround or maybe some recommendations how to handle
>this. You say that eval doesn't use LCG, so is there any other way to use IP
>that would use it? Or maybe there is a way to compile the script snipets only
>once and reuse them as most of the time they stay unchanged?
>
>Any help would be mostly appreciated as now we highly depend on this code.
>
>Szymon
>
>Martin Maly wrote:
>
>
>
>>Unfortunately, this is a known issue that we have on our to-do list.
>>The code generated by eval is not generated using lightweight codegen and as
>>such it is not garbage collected. As the result, you see the memory effects
>>you are describing.
>>We will definitely fix this by our 1.0 release, most likely even before Beta
>>and I'll try to find some time to look at this even before then depending on
>>my time.
>>
>>Martin
>>
>>-----Original Message-----
>>From: [EMAIL PROTECTED]
>>[mailto:[EMAIL PROTECTED] On Behalf Of Szymon
>>Kobalczyk
>>Sent: Friday, November 04, 2005 10:13 AM
>>To: [email protected]
>>Subject: [IronPython] Is this memory leak ?
>>
>>Hi,
>>
>>We just noticed a serious memory leak in our server application. It happens
>>after we execute some code that uses extensively dynamic scripting with
>>IronPython. After one run the allocation grows from 70MB to more then 500MB.
>>
>>I've investigated the memory heap using WinDbg and all paths lead to the
>>IronPython.Objects.Frame. All the variables that I passed to the PythonEngine
>>are kept in the dictionary inside these Frames. These Frames in turn are kept
>>in some static object[] array.
>>
>>In attached project I run in a loop some trivial script using engine Execute
>>method. You can attach to it using WinDbg and check that after the loop
>>completes there are 100 instances of Frame. Here is one sample from the
>>gcroot command:
>>
>>0:003> !gcroot 00b37918
>>Note: Roots found on stacks may be false positives. Run "!help gcroot" for
>>more info.
>>Scan Thread 0 OSTHread 13dc
>>Scan Thread 2 OSTHread 17fc
>>DOMAIN(00153570):HANDLE(Pinned):9313e4:Root:01ab4480(System.Object[])->
>>00b37918(IronPython.Objects.Frame)
>>
>>I also tried this with the evaluate method and the effect was the same.
>>Only with (my favorite) FastEval option the memory is not allocated. So this
>>could mean this leak occurs during code generation.
>>
>>I hope this is something that can be fixed quickly as we need to deploy this
>>solution to production.
>>
>>Note: I still work on .NET Beta 2 and IronPython 0.9.3. I also run the test
>>on the 0.9.4 version but results were the same.
>>
>>Thanks in Advance,
>>Szymon Kobalczyk.
>>
>>
>>PS: I post this mail again cause previously it had to large attachment and
>>was held for approval by moderator.
>>
>>
>>
>>
>>
>>
>
>
>
>
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com