IronLanguages / main

Work for this repo has moved to https://github.com/IronLanguages/ironpython2
1.16k stars 347 forks source link

HAPI: PythonEngine does not release ScriptScopes in RC1 #747

Open ironpythonbot opened 9 years ago

ironpythonbot commented 9 years ago
import clr  
clr.AddReference('Microsoft.Scripting')  
clr.AddReference('Microsoft.Dynamic')  
clr.AddReference('Microsoft.Scripting.Core')  
clr.AddReference('IronPython')  
import System  
from System import *  
import IronPython.Hosting  
from IronPython.Hosting import *  
import Microsoft.Scripting  
from Microsoft.Scripting import *  

engine = Python.CreateEngine()  
source = engine.CreateScriptSourceFromString("def Do(): pass",
SourceCodeKind.Statements);  
Console.WriteLine(String.Format("{0}\n", GC.GetTotalMemory(True)))  
for i in xrange(201):  
sc = engine.CreateScope()  
source.Execute(sc)  

sc.SetVariable("Inflate", System.Array.CreateInstance(int,1000000))  
sc = None  

if i % 10 == 0 :  
      GC.Collect()
      GC.WaitForPendingFinalizers()
      Console.WriteLine(String.Format("{0}", GC.GetTotalMemory(True)))

Log from this script execution:
4884440

8951508
49021304
89090556
129159796
169229076
209298532
249367688
289436940
329506180
369575420
409638812
449722636
489791888
517840620
513834600
513835216
513832004
513832656
513833296
513831992
513832632
Looks like engine does not release first 100 scopes

With ScriptScope from Runtime :

engine = Python.CreateEngine()  
source = engine.CreateScriptSourceFromString("def Do(): pass",
SourceCodeKind.Statements);  
Console.WriteLine(String.Format("{0}\n", GC.GetTotalMemory(True)))  
for i in xrange(201):  
sc = engine.Runtime.CreateScope()  
source.Execute(sc)  

sc.SetVariable("Inflate", System.Array.CreateInstance(int,1000000))  
sc = None  

if i % 10 == 0 :  
      GC.Collect()
      GC.WaitForPendingFinalizers()
      Console.WriteLine(String.Format("{0}", GC.GetTotalMemory(True)))

output different :

4884648

8952212
49026468
89100612
129173692
45018596
85091904
125164912
37009860
77082964
117156068
32995024
73082668
113155772
25000684
65073800
105146904
20987832
61060924
101134028
12978952
53049484

Only when I use compilation:

engine = Python.CreateEngine()  
source = engine.CreateScriptSourceFromString("def Do(): pass",
SourceCodeKind.Statements);  
Console.WriteLine(String.Format("{0}\n", GC.GetTotalMemory(True)))  
for i in xrange(201):  
comp = source.Compile()  
comp.Execute()  
sc = comp.DefaultScope  
comp = None  

sc.SetVariable("Inflate", System.Array.CreateInstance(int,1000000))  
sc = None  

if i % 10 == 0 :  
      GC.Collect()
      GC.WaitForPendingFinalizers()
      Console.WriteLine(String.Format("{0}", GC.GetTotalMemory(True)))

engine does not leaks
4885876

4956212
4956992
4957312
4957632
4957992
4958528
4958848
4959168
4959488
4959808
4960128
4974504
4974776
4975108
4975428
4975748
4976068
4976388
4976708
4977028
4971084

Work Item Details

Original CodePlex Issue: Issue 24735 Status: Active Reason Closed: Unassigned Assigned to: Unassigned Reported on: Sep 26, 2009 at 7:44 PM Reported by: dvemil Updated on: Feb 22, 2013 at 2:11 AM Updated by: jdhardy Test: hosting.stress.engine Thanks: dvemil

ironpythonbot commented 9 years ago

On 2010-02-13 13:49:04 UTC, dfugate commented:

Better but we're still leaking 400 bytes/script scope.