2017-07-17 32 views
1

例如:在使用數組時,python可能會丟失內存(如C++動態數組和指針)嗎?

list_1 = [1, 2, 3] 
list_2 = [4, 5, 6] 
list_3 = [7, 8, 9] 

list_3 = list_2 
list_2 = list_1 
list_1 = [0, 0, 0] 

# del list_3[:] # is this needed? 

print(list_1) # [0, 0, 0] 
print(list_2) # [1, 2, 3] 
print(list_3) # [4, 5, 6] 

list_3初始值[7, 8, 9]迷失在操作存儲器和需要被故意刪除與像在C++中,或者它被python解釋自動刪除del list_3[:]等附加命令?

回答

0

您不需要自己釋放該內存。它將通過口譯員的memory management自動處理。