Re: Memory.

From: Date: Mon, 21 Apr 2003 10:56:07 +0000
Subject: Re: Memory.
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-990@lists.php.net to get a copy of this message
On Mon, 21 Apr 2003, Vegard Munthe wrote: > I've asked these questions a number of other places. It seems no-one > really knows. So, even if this might not be the right list for these > questions, I hope someone can bare with me and help answer a few > questions, or direct me to someone or some doc that can. > > Questions: > > 1) Since there are no functions to tell the memory usage of variables and > objects, is there a way to calculate memory usage of variables and > objects? No, there is none. But there will be a function to show the total memory usage in PHP 5 : memory_get_usage(). > > 2) When a script loads different files as includes, does it take from the > memory_limit pool of memory? Yes > > 3) When leaving a function, are variables in the function's scope > freed? I.e. is the memory used by a function completely freed for > the rest of the script to reuse? It's returned for the rest of the script to reuse, BUT there will always be an allocated pool that will not be freed. > > 4) Is there any way to free memory used within a script? Does for > instance $var = ""; free the memory previously used by $var? Only a bit, doing $var = NULL will free the string contents, but not the variable container itself. > > 5) Is it not aa good idea to use objects if you plan to collect thousends > of them in PHP? Do they for some reason take up substantially more > memory than other variables? They do use quite a lot more memory then arrays, it just depends a little on how they are distributed, and which variables you see in mind for the relacement of objects. As a final word you might want to checkout Xdebug (http://xdebug.derickrethans.nl) which has a trace function (xdebug_start_trace and xdebug_dump_function_trace) to see how much memory a script uses per function call. (You will need to compile PHP with the --enable-memory-limit option for this to work though). Derick -- "my other box is your windows PC" ------------------------------------------------------------------------- Derick Rethans http://derickrethans.nl/ PHP Magazine - PHP Magazine for Professionals http://php-mag.net/ -------------------------------------------------------------------------

« previous php.internals (#990) next »