[PEAK] memory leaks & stuff

alexander smishlajev alex at ank-sia.com
Wed Sep 15 15:08:57 EDT 2004


Yaroslav Samchuk wrote, at 14.09.2004 20:52:

> On the last week we had discovered, that the application, which is
> developed by our team was leaking memory.

that's it.  the memory is leaking with nested AnyOf()s when the inner 
one does not include a _Sleeper.  the following script leaks memory with 
i/o events and Observable (or any derivatives), unless the the inner 
AnyOf includes eventLoop.sleep():

=== cut ===
import gc
import socket
import protocols
from peak.api import binding, events
from peak.running import commands, interfaces

class App(commands.AbstractCommand):

     mainLoop = binding.Obtain(interfaces.IMainLoop)
     eventLoop = binding.Obtain(events.IEventLoop)

     def _doEventLoop(self):
         _eventLoop = self.eventLoop
         _events = [events.Observable(), events.Observable()]
         #_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         #_events = [_eventLoop.readable(_sock), 
_eventLoop.exceptional(_sock)]
         _events.append(_eventLoop.sleep(1))
         # no leaks if inner AnyOf contains sleep:
         #_events.reverse()
         while True:
             ### leaking:
             _evt = reduce(events.AnyOf, _events)
             ### non-leaking:
             #_evt = events.AnyOf(*_events)
             yield _evt; events.resume()
             gc.collect()
             print "Total objects:", len(gc.get_objects())
     _doEventLoop = binding.Make(events.taskFactory(_doEventLoop),
         uponAssembly=True)

     def _run(self):
         return self.mainLoop.run()

if __name__ == "__main__":
     commands.runMain(App)
=== cut ===

as a temporary workaround, we unroll our events by composing new list 
from super().getEvent()._sources and all events we need to add, but we 
would like to avoid poking into private attributes.

best wishes,
alex.





More information about the PEAK mailing list