Forum Moderators: coopster

Message Too Old, No Replies

Clearing PHP array memory after use

         

tgilbert

1:59 am on Aug 20, 2007 (gmt 0)

10+ Year Member



Is it good practice to clear out arrays after you've used the data in them?

I am working with two PHP packages at the moment: a GPL content management system (CMS Made Simple) and a commercial shopping cart (Shop-Script Pro) and both of them seem to be constantly breaking through my PHP INI memory limit. I suspect memory leakage as the reason. I have upped the limit to 48M but still I get occasional demands beyond this limit. And the site is not even live yet!

So I have a few questions - I hope someone may have answers...

(1) When PHP warns that a memory limit has been exceeded, does it mean by the script itself, or by the server instance demand overall?

(2) Is there a simple way to monitor how much memory a script is using at the point when it it called (perhaps a function I can include and turn on/off as needed for debugging)?

(3) Is there a line of code I can add at the end of a script that clears all the arrays, etc., that script has created? Or does PHP do this nicely anyway?

FYI, I am an ASP programmer blindly feeling my way through PHP...

Tony

jatar_k

5:00 pm on Aug 20, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld tgilbert,

1. [php.net...]

This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.

2. you could do this via the command line, such as using ps

3. php cleans up when it finishes executing the script