python - Twisted memory leak when connect attempt failed -


i being tortured twisted memory leaks.

here code:

# python:  python 2.6.6 (r266:84297, aug 24 2010, 18:46:32) [msc v.1500 32 bit (intel)] on win32 # twisted: twisted-12.2.0.win32-py2.6 # os:      windows 7 (64bit) twisted.internet.protocol import protocol, clientfactory twisted.internet import reactor   class echo(protocol):     def __del__(self):         print 'echo.__del__'      def connectionmade(self):         print 'echo.connectionmade'         self.transport.write('hello world!')   class echoclientfactory(clientfactory):     def __del__(self):         print 'echoclientfactory.__del__'      def startedconnecting(self, connector):         print 'started connecting ...'      def buildprotocol(self, addr):         print 'connected. %r' % addr         return echo()      def clientconnectionfailed(self, connector, reason):         print 'connection failed.'   def connect(ip, port):     factory = echoclientfactory()     reactor.connecttcp(ip, port, factory)   ##start import gc gc.enable() gc.set_debug(gc.debug_leak)  # trying connect port not exist connect('127.0.0.1', 7777)  reactor.calllater(5, reactor.stop) reactor.run()  # show garbages print "gc.collect()" gc.collect() print 'gc.garbage:', len(gc.garbage)  i, item in enumerate(gc.garbage):     print '%d) %r' % (i + 1, item) 

after run, gc shows memory leak happen:

after run, gc shows memory leak happen:

after run, gc shows memory leak happen:

started connecting ... connection failed. echoclientfactory.__del__ gc.collect() gc: collectable <client 02cea7b0> gc: collectable <dict 02cefc00> gc: collectable <tuple 02b13fd0> gc: collectable <list 02cd2558> gc: collectable <instancemethod 02818e40> gc: collectable <instancemethod 02cf04b8> gc: collectable <tuple 02b205f8> gc.garbage: 7 1) <<class 'twisted.internet.tcp.client'> ('127.0.0.1', 7777) @ 2cea7b0> 2) {'_tempdatabuffer': [], 'protocol': none, '_tempdatalen': 0, 'realaddress': ('127.0.0.1', 7777), 'doread': <bound method client.doconnect of <<class 'twisted.internet.tcp.client'> ('127.0.0.1', 7777) @ 2cea7b0>>, 'dowrite': <bound method client.doconnect of <<class 'twisted.internet.tcp.client'> ('127.0.0.1', 7777) @ 2cea7b0>>, 'reactor': <twisted.internet.selectreactor.selectreactor object @ 0x02699d50>, 'addr': ('127.0.0.1', 7777)} 3) ('127.0.0.1', 7777) 4) [] 5) <bound method client.doconnect of <<class 'twisted.internet.tcp.client'> ('127.0.0.1', 7777) @ 2cea7b0>> 6) <bound method client.doconnect of <<class 'twisted.internet.tcp.client'> ('127.0.0.1', 7777) @ 2cea7b0>> 7) ('127.0.0.1', 7777) 

only happened when connect failed.

any ideas on why?

adding __del__ program adds object leaks it. presence of __del__ on object in cycle prevents entire cycle being collected.

try debugging actual program without using __del__ anywhere. or if actual program uses __del__, try getting rid of it.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -