By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

php memory questions

P: n/a
I'm using php 4.3, and I"m wondering when is it a good idea to use this
unset() function to free a variable?

Also, what happens internally when a variable is set in one place, then
reset in another -- for instance:

$a = "some string";

and later on in the script I have:

$a = "a different string";

What happens to "some string" -- is it still floating around in memory
(without any references to it)? Or is it garbage collected & memory
freed? Should I use unset($a) to free "some string" before resetting
$a to something different?

Thanks.
Chris

Jul 5 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
cm******@yahoo.com wrote:
I'm using php 4.3, and I"m wondering when is it a good idea to use this
unset() function to free a variable?
It rather depends what for and where you're using it.

Assuming its for generating web pages, called as CGI, fast CGI or module,
then don't worry - the runtime memory gets blown away after servicing each
request.

IME PHP does a very good job of tracking what memory it has allocated - I've
run servers fielding millions of hits per day and only had to take them
down for patching.

C.
Jul 5 '06 #2

P: n/a
For memory variables you shouldnt have to do anything. PHP handles
everything through garbage collection.

But for database resources, sometimes you may have to. E.g. handles to
databases and tables. If you don't, the handle gets destroyed but the
allocated resource is still there in memory and repeated calls to
connect/execute you will have a memory leak.

Always close handles.
Colin McKinnon wrote:
cm******@yahoo.com wrote:
I'm using php 4.3, and I"m wondering when is it a good idea to use this
unset() function to free a variable?

It rather depends what for and where you're using it.

Assuming its for generating web pages, called as CGI, fast CGI or module,
then don't worry - the runtime memory gets blown away after servicing each
request.

IME PHP does a very good job of tracking what memory it has allocated - I've
run servers fielding millions of hits per day and only had to take them
down for patching.

C.
Jul 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.