Sadece dizi ya da tüm nesneleri unset nesneler dizisi unsetting mu?

3 Cevap php

Ben nesneleri bir dizi var. Ben unset ($ dizi) ararsanız, olacak o unset dizi VE dizideki tüm nesneleri ya da sadece dizi? Kullanıcının bu nesneler başka hiçbir başvurulan varsayalım.

3 Cevap

Bu dizi nesnesine sadece başvuru içeriyorsa, o zaman evet. Aksi halde hiçbir. Ayrıca, PHP Dökümantasyonundan akılda tutulması gereken şey:

unset() does just what it's name says - unset a variable. It does not force immediate memory freeing. PHP's garbage collector will do it when it see fits - by intention as soon, as those CPU cycles aren't needed anyway, or as late as before the script would run out of memory, whatever occurs first.

GSTO doğru ... Sadece PHP garbadge toplayıcı belleği boşaltın. unset () bir değişken ya da NULL olarak ayarlayarak (CPU döngüsü fiyata) "garbadge toplama" süreci hızlandırabilir ancak doğrudan bazı bellek boşaltmak için hiçbir yolu yoktur (à la C + + nerede aslında belleği serbest olacak "delete") .

Ben bir forumda bir süre önce benzer bir soru sordu ve bu ne var:

Fou-Lu@codingforums.com Gönderen:

Unset free's its resources, and any free request does the same (like mysql_free_result). Yes, this allows the collector to take care of it. But until the collection process occurs, it will ignore any referenced variables. So, if a pass of the gc sees that a variable is referenced, it will ignore it. If it sees that it has been freed, it will take it, but if you have a block of data that is not freed and not used than it will sit in memory until script termination (less relevant nowadays on modern high ram systems). Using unset on an array is sufficient for the gc to take it. I'll see if I can find it in the source, but I would presume that all HashMaps used by the C reference pointers and not values, so the values themselves are not of any relevance since a null pointer is the same size anyway. I'd also suspect that once the GC gets to the hashmap that it will go through and release every zval associated with it and will perform write-on-copy for any individual pointer associated with a particular variable (fancy way of saying that it won't release any index that is referenced by another variable).

http://www.codingforums.com/showthread.php?t=184164

Script yürütme bitirene kadar bellek serbest değil gibi görünüyor. http://bugs.php.net/bug.php?id=48368