Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:990 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28467 invoked from network); 21 Apr 2003 10:56:11 -0000 Received: from unknown (HELO jdi.jdimedia.nl) (212.204.192.51) by pb1.pair.com with SMTP; 21 Apr 2003 10:56:11 -0000 Received: from jdi.jdimedia.nl (jdi.jdimedia.nl [212.204.192.51]) by jdi.jdimedia.nl (8.12.4/8.12.4) with ESMTP id h3LAu7fk003102; Mon, 21 Apr 2003 12:56:08 +0200 Date: Mon, 21 Apr 2003 12:56:07 +0200 (CEST) X-X-Sender: derick@jdi.jdimedia.nl To: Vegard Munthe cc: PHP Developers Mailing List In-Reply-To: <20030421124532.F86580-100000@unity.copyleft.no> Message-ID: References: <20030421124532.F86580-100000@unity.copyleft.no> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [PHP-DEV] Memory. From: derick@php.net (Derick Rethans) 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/ -------------------------------------------------------------------------