[IronPython] clr.AddReference effect how GC work ?!?!?!?

Sakesun Roykiattisak sakesun at boonthavorn.com
Wed Apr 23 09:23:09 CEST 2008


Hi,

     My today attempt to fight with over-memory usage in my IronPython
server application, reveal a very strange behavior of IronPython
(both 1.1 and 2.0b)  I'll demonstrate with the following script:  
"loopit.py"


##### loopit.py ###########################

import clr
#clr.AddReference('System')

class MyObj(object):
     def __del__(self): print 'gone'

def run():
     from System.Threading import Thread
     from System import GC
     while True:
         MyObj()
         Thread.Sleep(100)
         GC.Collect()

run()

###########################################


try to run this script you'll see a stream of 'gone' print out.
However, if you uncomment the line "clr.AddReference('System')"
and rerun it again the system will simple halt, memory usage
will keep raising. Until you press Ctrl-C, then the you will
see the pending 'gone' stream out.

I've tried with

clr.AddReference('System.Data')
clr.AddReference('System.Xml')

and the behaviour is the same for any Assembly.
This is really weird. Why should clr.AddReference effect how
GC work ?

And I believe this is indeed the true source of memory problem I'm facing.

Hope someone explain me why.

Thanks
-------------- next part --------------
A non-text attachment was scrubbed...
Name: loopit.py
Type: text/x-python
Size: 261 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080423/129d5e9d/attachment.py>


More information about the Ironpython-users mailing list