我执行以下代码。清除列表时,出现内存泄漏。 如何清除列表和内存?
q = Queue()
lines_list = []
while True:
try:
line = q.get() # get dict
except IndexError:
continue
if len(line) > 0:
lines_list.append(line.copy())
if datetime.now().minute - epoch_start == EPOCH_PERIOD:
epoch_start = datetime.now().minute
lines_list.clear()
内存分析器:
Line # Mem usage Increment Line Contents
================================================
...
89 82.2 MiB 0.1 MiB q = Queue()
90 82.2 MiB 0.0 MiB lines_list = []
91 82.2 MiB 0.0 MiB while True:
92 110.0 MiB 0.0 MiB try:
93 110.0 MiB 22.9 MiB line = q.get() # get dict
94 except IndexError:
95 continue
96 110.0 MiB 1.5 MiB if len(line) > 0:
97 110.0 MiB 2.4 MiB lines_list.append(line.copy())
98 110.0 MiB 0.0 MiB if datetime.now().minute - epoch_start == EPOCH_PERIOD:
99 110.0 MiB 0.0 MiB epoch_start = datetime.now().minute
100 111.7 MiB 0.0 MiB lines_list.clear()