# Memory.

- Thread: https://externals.io/message/989
- Original archive: https://news-web.php.net/php.internals/989
- Started by Vegard Munthe on 2003-04-21T10:49:03+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #989 — Vegard Munthe — 2003-04-21T10:49:03+00:00

URL: https://externals.io/message/989#989

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?

2) When a script loads different files as includes, does it take from the
   memory_limit pool of memory?

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?

4) Is there any way to free memory used within a script? Does for
   instance $var = ""; free the memory previously used by $var?

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?

Thank you for any answers, or help in finding the right people to ask.

-- Vego

---

## #990 — Derick Rethans — 2003-04-21T10:56:07+00:00

URL: https://externals.io/message/989#990 · In reply to: #989

> 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/

---

## #1040 — Derick Rethans — 2003-04-25T12:40:42+00:00

URL: https://externals.io/message/989#1040

> Il lun, 2003-04-21 alle 12:56, Derick Rethans ha scritto:
> 
> > […]
> 
> When ?

It's already in, but you need to enable --enable-memory-limit I think.

Derick

-- 
                                        "my other box is your windows PC"
-------------------------------------------------------------------------
 Derick Rethans                                 http://derickrethans.nl/ 
 PHP Magazine - PHP Magazine for Professionals       http://php-mag.net/
