Re: free allocated memory: HOW ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Arthur Erdös wrote:
Hello all,

is there a way to free memory allocated by variables in PHP?? This is a very important issue concerning long running scripts...

I have a script that generates > 5000 Newsletters and when the script finishes it uses 1.8 GB (!!) of RAM. Although I am using unset() to clean up variables (tried with $var = null too).

I'd place stuff like:

error_log('in file ' . __FILE__ . ' at line ' . __LINE__ . '; memory usage is ' . (memory_get_usage() / 1024) . ' kb');

all over the place and work out where it's jumping, then work out why it's jumping so much.

Work out your biggest jumps first (they will have the most benefit), then work out smaller jumps and slowly work down the chain until it stays at a reasonable level.


Also as Richard pointed out, if you're including images and/or attachments in a newsletter, that increases memory a lot. You need to base64_encode the image/attachment before it will work in an email program - and encoding it takes up around an extra 30% over the original data (see http://php.net/base64_encode).

So what starts out as a 100k image will most likely end up as almost 130k+ in memory.

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux