472,119 Members | 962 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Memory leak when creating lots of object

Hello,

I have a program that create and pop an object off a queue, but it is
experiencing some memory leakage. I have been unable to detect where
the memory leakage occur. The strange thing is when i replace the
object creation with a plain integer/string, the leak goes away...
Here's the code I used as my test:
import Queue
import threading
import time

q = Queue.Queue(0)

class PDU:
def __init__(self, name=''):
self.name = name

class qTest(threading.Thread):
def __init__(self, name=''):
threading.Thread.__init__(self)
self.name = name
self.threadContinue = True

def run(self):
count = 0
while self.threadContinue:
pdu = q.get(True)
del pdu
count+=1
#print count
if q.qsize() == 0:
print "Total get in bulk", count
count = 0

def stop(self):
self.threadContinue = False
q.put(1)
if __name__ == "__main__":
try:
qt = qTest()
qt.start()
loopCount = 1000
while True:
for i in range(loopCount):
pdu = PDU()
## pdu = 1
q.put(pdu)
time.sleep(5)

except KeyboardInterrupt:
print "Keyboard interrupted. Program exit."
except Exception, why:
print why

if qt.isAlive():
qt.stop()

I can see the memory usage increases slowly in Task Manager under XP,
but do not know why. Anyone help?

Thank you.

Aug 14 '07 #1
3 2464
On 14 Aug, 05:57, Godzilla <godzillais...@gmail.comwrote:
Hello,

I have a program that create and pop an object off a queue, but it is
experiencing some memory leakage. I have been unable to detect where
the memory leakage occur. The strange thing is when i replace the
object creation with a plain integer/string, the leak goes away...
Here's the code I used as my test:
[...]
I can see the memory usage increases slowly in Task Manager under XP,
but do not know why. Anyone help?
I tried your code on my (Windows XP SP2, Python 2.5) system. No memory
leak here - I left it running for over 5 minutes and memory usage was
static at just under 4MB.

Do you see memory growth with precisely this code? Over what period?
How much?

Paul.

Aug 15 '07 #2

"Godzilla" <go***********@gmail.comwrote in message
news:11**********************@i38g2000prf.googlegr oups.com...
| What should I do next? Can I force garbage collection manually? If so,
| how do I do that?

Read doc for gc module. I think
import gc
gc.collect()

Aug 17 '07 #3
On 17 Aug, 04:51, Godzilla <godzillais...@gmail.comwrote:
On Aug 16, 1:13 am, Paul Moore<p.f.mo...@gmail.comwrote:
On 14 Aug, 05:57, Godzilla <godzillais...@gmail.comwrote:
Do you see memory growth with precisely this code? Over what period?
How much?

I have it running for more than 1 hour... the main application
software runs for about 50 days non stops and the memory just keep
growing...
I'm sorry. Just to be precise, how long would I need to run the code
you posted to see a memory growth?
What should I do next? Can I force garbage collection manually? If so,
how do I do that?
As Terry suggested, look at the gc module (gc.collect). But on
inspection, I don't see a memory leak that would be cured by forcing a
collection, which is why I'd like to reproduce the problem before
offering suggestions...

Paul.

Aug 18 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Debian User | last post: by
10 posts views Thread by Matt Kruse | last post: by
7 posts views Thread by Jon Davis | last post: by
8 posts views Thread by Adrian | last post: by
7 posts views Thread by Salvador | last post: by
11 posts views Thread by Alex | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.