[英]spyder does not free memory after running code
I am running a python code in Spyder. 我在Spyder中运行python代码。 When i start the code memory is on 22%, but after finishing the code the memory remain on 64%. 当我启动代码时,内存占22%,但完成代码后,内存仍占64%。 I must restart kernel or end process from task manager to back to 22%. 我必须重新启动内核或结束从任务管理器到22%的进程。 Why this situation occurs? 为什么会出现这种情况? and how to handle it? 以及如何处理?
I attached the my code for more details. 我附上了我的代码以获取更多详细信息。
import csv
import re
import openpyxl
import os
papers_dir = os.listdir('Persian - Copy')
#Journals
for y in papers_dir:
papers = []
if y.endswith('.xlsx'):
wb = openpyxl.load_workbook('Persian - Copy/'+y)
sheet = wb.active
for z in range(2, sheet.max_row+1):
id_ = str(sheet.cell(row=z, column=1).value)
field = str(sheet.cell(row=z, column=2).value).replace('ي','ی').replace('ك','ک').split()
field1 = str(sheet.cell(row=z, column=4).value).replace('ي','ی').replace('ك','ک').replace('None', '').split('،')
field2 = re.sub(re.compile('<.*?>'), '', str(sheet.cell(row=z, column=3).value))
field2 = field2.replace('ي','ی').replace('ك','ک').replace('لطفا برای مشاهده چکیده به متن کامل (PDF) مراجعه فرمایید.','').replace(' لطفا برای مشاهده چکیده به متن کامل (PDF) مراجعه فرمایید.','').replace('None', '').replace('.',' ').split()
f = [id_, (field + field1 + field2)]
papers.append(f)
wb.close()
sheet = 0
print(y)
#Making Unique Rows
uniques = []
x_0 = []
for x in papers:
if x[0] not in x_0:
x_0.append(x[0])
uniques.append(x)
with open('all.csv', 'a+', newline='', encoding='UTF-16') as un:
writer = csv.writer(un, delimiter= '\t')
for x in uniques:
writer.writerow(x)
papers = 0
uniques = 0
x_0 = 0
f = 0
To combat this I used pickle to save my objects and then I restarted the console every time. 为了解决这个问题,我使用了pickle保存对象,然后每次都重新启动控制台。
It is pedantic but it helps combat the memory usage. 它是徒劳的,但有助于解决内存使用问题。 The developers are working on it I think but this issue has been around for a year or so. 我认为开发人员正在研究它,但是这个问题已经存在了一年左右。
关闭运行代码的ipython控制台应释放它使用的内存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.