jimfog Posted September 23, 2012 Share Posted September 23, 2012 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 More sharing options...
boen_robot Posted September 23, 2012 Share Posted September 23, 2012 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 More sharing options...
jimfog Posted September 23, 2012 Author Share Posted September 23, 2012 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 More sharing options...
boen_robot Posted September 23, 2012 Share Posted September 23, 2012 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 More sharing options...
jimfog Posted September 23, 2012 Author Share Posted September 23, 2012 if we disable the collector, are error messages going to output? Link to comment Share on other sites More sharing options...
boen_robot Posted September 23, 2012 Share Posted September 23, 2012 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 More sharing options...
jimfog Posted October 1, 2012 Author Share Posted October 1, 2012 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 More sharing options...
Don E Posted October 1, 2012 Share Posted October 1, 2012 (edited) Yes. There you should find the memory setting that is allowed for a PHP script. Search for: memory_limit Edited October 1, 2012 by Don E Link to comment Share on other sites More sharing options...
justsomeguy Posted October 1, 2012 Share Posted October 1, 2012 http://www.php.net/manual/en/function.memory-get-peak-usage.php Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now