From:             fransson at fransson dot de
Operating system: Windows XP
PHP version:      4.3.11
PHP Bug Type:     Performance problem
Bug description:  No garbage collection when iterating large loops

Description:
------------
PHP runs out of memory when iterating large loops. It seems that it does
not free unused memory. The Windows Task Manager indicates that it tries
to allocate more than 2 Gigabytes of memory (on my P4 with 1 Gigabyte)
before crashing with an access violation.

In my opinion this is a performance problem in the first place.  The crash
does help in this case because the machine becomes usable again.

Although I guess it is not, this problem might be related to the MySQL
interface because the loops which are causing my troubles are of the
following structure:

while ($row = mysql_fetch_array($set, MYSQL_ASSOC)) {
  ...
}

I guess that the data being stored in the variable $row with each
iteration is never being freed up by php, although it can never be
referenced again after the next iteration has overwritten the old
reference.

To be more explicit:
1. Before the execution of the while-loop, $row does not even exist and
therefore does not consume any memory.
2. During the execution of the first iteration of the while-loop, $row
consumes only enough memory to hold a single row of the result set (which
might be around 20 KB in my case).
3. During the execution of the second iteration, $row is being overwritten
with a new row of the result set. Its previous value is not accessible any
more, but nevertheless consumes memory. Therefore, assuming a memory
consumption of about 20 KB per row, the total memory consumption during
the second iteration is 40 KB. 20 KB of these are completely wasted since
they remain inaccessible to the application.
4. The larger the result set, the larger the memory wasted. If it is large
enough, it will slow down and crash any machine. In my case, the result set
holds about 50,000 records.



-- 
Edit bug report at http://bugs.php.net/?id=32829&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32829&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=32829&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=32829&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32829&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32829&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32829&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32829&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32829&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32829&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32829&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=32829&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=32829&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32829&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32829&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32829&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32829&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32829&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32829&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32829&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32829&r=mysqlcfg

Reply via email to