Here is a small script (script1) which highlight a traistui memory leaks : the script open and close many times a window. Running in a loop, we can observe that the memory grows indefinitely. I observe this result under windows 7 64 bits with traistui 4.2.0 and 4.2.1 and under linux and tratsui 4.2.1 for both qt4 and wx backends.
Under linux, the script starts with around 45 MB RSS memory and ends with 500 MB RSS memory after 10 000 open / close ui window.
I am not sure to point the real problem, but running guppy, I observe that the number of dict containing traits.trait_notifiers.FastUITraitChangeNotifyWrapper and weekref objects increased at the same rate than the number of opened / closed windows.
Using a simple ack script (script2) we can observe that 3 FastUITraitChangeNotifyWrapper are created for each window but only one is deleted (dispose method called).
script 1:
import gc, guppy, traceback
i=0
from traits.api import HasTraits, Str, List, Instance, Button, Float, Int
from traits.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'wx'
from traitsui.api import View, Item, Controller
from traits.trait_notifiers import ui_handler
import time, threading, numpy
delay = 0.2
heap = guppy.hpy()
person_view = View(
Item(name='name'),
buttons=['OK']
)
class Person(HasTraits):
name = Str('No name')
class PersonController( Controller ):
i = Int
def init_info(self, info):
global i
self.info = info
i += 1
self.i = i
threading.Thread(target=self.t).start()
def t(self):
global i
time.sleep(delay)
ui_handler(self._on_close, self.info)
if self.i==0:
heap.setrelheap()
if self.i % 100 == 0:
gc.collect()
print heap.heap()
class Family(HasTraits):
father = Instance(Person)
run = Button
traits_view = View(
Item('run'),
)
def _run_fired(self):
threading.Thread(target=self.t).start()
def t(self):
person_controller = PersonController()
for i in range(10000):
time.sleep(delay)
def h():
self.father.edit_traits(view=person_view, handler=PersonController())
ui_handler(h)
family = Family(father=Person(name='toto'))
family.configure_traits()
script 2 (put at the beginning of script 1)
import traits.trait_notifiers
old_FastUITraitChangeNotifyWrapper = traits.trait_notifiers.FastUITraitChangeNotifyWrapper
i=0
class Notifier(old_FastUITraitChangeNotifyWrapper):
def __init__(self, *args, **kw):
global i
self.i = i
i+=1
print 'create notifier',i
old_FastUITraitChangeNotifyWrapper.__init__(self, *args, **kw)
def dispose(self):
print 'notifier dispose', self.i
old_FastUITraitChangeNotifyWrapper.dispose(self)
traits.trait_notifiers.FastUITraitChangeNotifyWrapper = Notifier
Here is a small script (script1) which highlight a traistui memory leaks : the script open and close many times a window. Running in a loop, we can observe that the memory grows indefinitely. I observe this result under windows 7 64 bits with traistui 4.2.0 and 4.2.1 and under linux and tratsui 4.2.1 for both qt4 and wx backends.
Under linux, the script starts with around 45 MB RSS memory and ends with 500 MB RSS memory after 10 000 open / close ui window.
I am not sure to point the real problem, but running guppy, I observe that the number of dict containing traits.trait_notifiers.FastUITraitChangeNotifyWrapper and weekref objects increased at the same rate than the number of opened / closed windows.
Using a simple ack script (script2) we can observe that 3 FastUITraitChangeNotifyWrapper are created for each window but only one is deleted (dispose method called).
script 1:
script 2 (put at the beginning of script 1)