faqts : Computers : Programming : Languages : PHP : kms : General

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

11 of 18 people (61%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Is the memory used by variables freed automatically during script execution?
Do I need to explicitly free the memory used by variables in PHP scripts?

Jul 3rd, 1999 20:02
Nathan Wallace, Zeev Suraski


You shouldn't worry about PHP variables consuming memory, except for
very specific cases when you use indirect reference to variable names
and reference different variables in every iteration (extremely rare).

If you use the same variables all throughout the loop (which is almost
always the case), only the memory necessary to store the current value
of the variable(s) remains allocated.  The old values are freed and do
not consume memory.