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:
-
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? -
When a script loads different files as includes, does it take from the
memory_limit pool of memory? -
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? -
Is there any way to free memory used within a script? Does for
instance $var = ""; free the memory previously used by $var? -
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?
Thank you for any answers, or help in finding the right people to ask.
-- Vego
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:
- 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().
- When a script loads different files as includes, does it take from the
memory_limit pool of memory?
Yes
- 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.
- 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.
- 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/