看板 PHP 關於我們 聯絡資訊
sorry 貼錯程式碼了 <?php function test() { $handle = fopen('/tmp/testing123.txt', 'a+'); return $handle; } for($i = 0; $i < 1000000000000; $i++) { $handle[$i] = test(); fclose($handle[$i]); } ?> 我想問這樣子為什麼記憶體會一直長~? 而不會在fclose後就放掉? 感謝~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.165.12.187
worry:$handle裡面的垃圾還是佔有空間的 04/04 21:44
gname:不能強制UNSET? 04/05 00:23
qwertmn:$handle[$i] = test(); 這為什麼要用array ? 04/05 05:48
chenlarry:php的GC不會完全清掉,他會保留一些記憶體的參考位置 04/05 11:20
chenlarry:以便之後使用,詳情請參考下面官方討論串 04/05 11:21
chenlarry:https://bugs.php.net/bug.php?id=45954 04/05 11:21
MOONRAKER:樓上贊 04/06 01:42
dogmimi:以上 感謝啦!!!!! 04/06 12:08
i9100:我覺得.... $handle[1000000000000]你覺得需要用多少記憶體? 04/24 17:22
i9100:就算資料結構不算...index就到1T了..你記憶體有這麼大? 04/24 17:23
i9100:另外,fclose()應該是因為古老時代file descripter是有上限 04/24 17:24
i9100:的。(OS常用作法就是把各種周邊視為檔案)記得dos似乎是20個 04/24 17:25
i9100:而其中3拿來給stdin,stdout,stderr。所以你的程式照20年前標 04/24 17:26
i9100:準來看,若不fclose(),你開啟第18個檔案就會資源不足 04/24 17:26
i9100:若沒記錯,20年前unix c也是只能開啟17個檔案。以上觀念說明 04/24 17:27