Hi @Windspar,
Thank you for reply and I thought your idea is great.
I did some experiment today. My observation is that the q size is empty, however the system memory is occupied about 84M. Here is some code to reproduce my result.
Ubuntu 16.04, python 2.7.12
First shoot: del
Thank you for reply and I thought your idea is great.
I did some experiment today. My observation is that the q size is empty, however the system memory is occupied about 84M. Here is some code to reproduce my result.
Ubuntu 16.04, python 2.7.12
First shoot: del
import Queue q = Queue.Queue() length = 10000000 buffer_size = 1000 index = 0 while index < length: q.put_nowait(1) index += 1 key = raw_input('finish insert, press key to pop') while q.qsize() > buffer_size: a = q.get() del a print 'after pop, q size = ', q.qsize() raw_input('let me del the q') del q key = raw_input('finish delete')Second shoot: clear()
import Queue q = Queue.Queue() length = 10000000 buffer_size = 1000 index = 0 while index < length: q.put_nowait(1) index += 1 key = raw_input('finish insert, press key to pop') while q.qsize() > buffer_size: a = q.get() del a print 'after pop, q size = ', q.qsize() raw_input('let me del the q') with q.mutex: q.queue.clear() print 'q size = ', q.qsize() key = raw_input('finish delete')Third shoot: Queue()
import Queue q = Queue.Queue() length = 10000000 buffer_size = 1000 index = 0 while index < length: q.put_nowait(1) index += 1 key = raw_input('finish insert, press key to pop') while q.qsize() > buffer_size: a = q.get() del a print 'after pop, q size = ', q.qsize() raw_input('let me del the q') q = Queue.Queue() print 'q size = ', q.qsize() key = raw_input('finish delete')Fourth shoot: gc.collect()
import Queue import gc q = Queue.Queue() length = 10000000 buffer_size = 1000 index = 0 while index < length: q.put_nowait(1) index += 1 key = raw_input('finish insert, press key to pop') while q.qsize() > buffer_size: a = q.get() del a print 'after pop, q size = ', q.qsize() raw_input('let me del the q') #del q #with q.mutex: # q.queue.clear() q = Queue.Queue() print 'q size = ', q.qsize() raw_input('let me gc.collect') gc.collect() raw_input('how about now?')These four ways would not release the memory in the queue.Can anyone tell me what I'm doing wrong? Many thanks!
(Dec-29-2017, 04:47 PM)Windspar Wrote: http://effbot.org/pyfaq/why-doesnt-pytho...object.htm
https://stackoverflow.com/questions/1545...-in-python
You could try create a new queue. Swap it out for the old one. Clear old queue then del old queue.