Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52894 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14039 invoked from network); 4 Jun 2011 21:38:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jun 2011 21:38:06 -0000 Authentication-Results: pb1.pair.com smtp.mail=mike.vanriel@naenius.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=mike.vanriel@naenius.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain naenius.com designates 83.96.159.14 as permitted sender) X-PHP-List-Original-Sender: mike.vanriel@naenius.com X-Host-Fingerprint: 83.96.159.14 linux35.webawere.nl Linux 2.6 Received: from [83.96.159.14] ([83.96.159.14:58616] helo=linux35.webawere.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 03/93-14012-CB5AAED4 for ; Sat, 04 Jun 2011 17:38:05 -0400 Received: from localhost ([127.0.0.1] helo=webmail.naenius.com) by linux35.webawere.nl with esmtpa (Exim 4.76) (envelope-from ) id 1QSyXg-0001uI-P3; Sat, 04 Jun 2011 23:38:01 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 04 Jun 2011 23:38:00 +0200 To: PHP Internals Message-ID: X-Sender: mike.vanriel@naenius.com User-Agent: Roundcube Webmail/0.5.2 X-Antivirus-Scanner: Seems clean. You should still use an Antivirus Scanner Subject: Trying to find out where the memory went From: mike.vanriel@naenius.com (Mike van Riel) Dear Internals, During development of DocBlox I encountered a (for me) unusual situation with regards to memory usage. I hope you can shed some light on this for me as I do not understand. The situations is as follows: I have a php file containing about 53 KLOC (including whitespace and comments), which is about 2.1MB in size. When I execute the memory_get_peak_usage after running the token_get_all method on its content it reports that 232MB of RAM have been used in the process. I am having trouble understanding how 244003984B (232MB) RAM could be used. The following is what I have calculated: * 640.952B to start with (measured); * 2.1MB to load the file contents into memory using file_get_contents * 68 bytes for the resulting array * 68 bytes for each child array representing a token * 68 bytes for each element in a token array (which can be either 1 or 3, depending whether it is actually a token or literal) * 2.1MB in total for the string contents of the token literals / contents (equivalent to the byte size of the file) I have used the count method to retrieve the number of tokens (276697) and come to the following sum (everything is retrieved and calculated in bytes): 640952+2165950+68+(276697*68)+(276697*3*68)+2165950=80234436 = 76M This is a worst case formula where I assume that every token in the array consists of 3 elements. Based on this calculation I would be missing 156MB of memory; anybody know where that went? I used the following snippet of code for my tests: var_dump(memory_get_peak_usage()); $tokens = token_get_all(file_get_contents('')); var_dump(count($tokens)); var_dump(memory_get_peak_usage()); I hope this mail did not scare anyone ;) Kind regards, Mike van Riel