Jump to content

garbage collector


jimfog
 Share

Recommended Posts

Suppose, we assign a string to a variable $xand then, afterwards we assign another,different string, again to variable $x. Is the first value, the one we assigned at the beginning, collected by the PHP garbage collector?

Link to comment
Share on other sites

Yes. Of course, from your point of view, the value will be immediately replaced, since every $x will point at the new value.

Link to comment
Share on other sites

So...I will not see any error message I mean, the garbage collector will do its job quietly in the background.

Link to comment
Share on other sites

Of course. PHP is not C (I mean, not from a PHP developer's perspective), where even strings are actually arrays of chars, and thus need to be taken care for.No. In PHP, and most languages with a garbage collector, whether you're using strings or objects, the garbage collector takes care of freeing the memory when not needed and keeping references correct, all in the background, and thus leaving you completely oblivious to the fact.

Link to comment
Share on other sites

if we disable the collector, are error messages going to output?

Link to comment
Share on other sites

No, but you'll start to quickly go out of memory (or at least have a lot of it consumed) unless you manually call unset() on every variable (including individual array members) that you're no longer using. This can be especially troublesome at loops in which you change the value of a non-numeric variable on every iteration. IF you end up exhausting the web server's memory, THEN you'll see an error message (which you'd see even with garbage collection enabled, if there's no garbage to be collected, but too much of an actual in-use memory).See this page of the manual (in fact, check out the whole section on GC) for details.It's important to note that with or without garbage collection enabled, any memory allocated during a request is cleaned after the request is over. This is something PHP doesn't let you alter in any way, for obvious reasons.

Link to comment
Share on other sites

  • 2 weeks later...

From where I am going to learn what is the amount of memory allocated to PHP.In php.ini?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...