4
我剛安裝了lxml
,使用easy_install
在Ubuntu12.04電腦上安裝了Python 3.2.3。 lxml
是最新版本3.0Alpha。在Ubuntu12.04中使用Python3進行lxml內存泄露
我嘗試下面的代碼:
import lxml.html
def proc_tweet(ss):
html=lxml.html.fragment_fromstring(ss)
ps=html.xpath("//p[@node-type='feed_list_content']")
def test():
ss=''
f=open('test')
for l in f: ss+=l.strip()
f.close()
while True: proc_tweet(ss)
if __name__=='__main__':
test()
在這裏,「測試」是一個文件,包括一個簡短的HTML片段:
<dl action-type="feed_list_item" mid="3409553360609821" class="feed_list W_linecolor">
<dd class="content">
<p node-type="feed_list_content">This is a drill.</p>
</dd>
<dd class="clear"></dd>
</dl>
的問題lxml
吃我所有的記憶隨着時間的推移通過。我試過這個
del ps
del html
它不起作用。有人知道爲什麼
你是如何衡量*「吃我所有的記憶」*?操作系統根據請求將內存分配給程序,但除非需要在其他地方再次使用,否則不會回收內存,即使程序再次釋放了該內存,所以*可能就是這種情況。 –
當我評論ps = html.xpath(「// p [@ node-type ='feed_list_content']」) 這一行。內存使用情況正常。 – LaoMao
我的意思是它最終會使用8G內存。 Python自動管理內存使用情況。它應該自動釋放內存。但它不在我的代碼中。 – LaoMao