Bug #65300 [Opn->Nab]: Memory leak when initializing objects
| From: | johannes@php.net | Date: | Sat, 20 Jul 2013 18:31:49 +0000 |
| Subject: | Bug #65300 [Opn->Nab]: Memory leak when initializing objects | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-180376@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65300&edit=1
ID: 65300
Updated by: johannes@php.net
Reported by: zlobnygrif at gmail dot com
Summary: Memory leak when initializing objects
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: debian/ubuntu
PHP Version: 5.4.17
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
When creating the class we "prefill" the properties. Thanks to copy-on-write we
(generally) don't have to copy these values when creating an instance of the object. When
reassigning them with the same value those default values will e replaced. We don't compare the
values.
Previous Comments:
------------------------------------------------------------------------
[2013-07-20 06:14:03] zlobnygrif at gmail dot com
Description:
------------
If I set object property run-time it uses more memory than equal default property value.
Test script:
---------------
printf("PHP %s %s\n\n", PHP_VERSION, PHP_OS);
class Order {
public $id = '123';
public $number = '1234';
public $date = '12345';
}
$orders = [];
printf("Test1\nMem before: %.2f mb\n", memory_get_usage(true) / 1024 / 1024);
for ( $i = 0; ++$i < 100000; )
{
$order = new Order;
$orders[] = $order;
}
printf("Mem after: %.2f mb\n\n", memory_get_usage(true) / 1024 / 1024);
unset($orders, $i);
$orders = [];
printf("Test2\nMem before: %.2f mb\n", memory_get_usage(true) / 1024 / 1024);
for ( $i = 0; ++$i < 100000; )
{
$order = new Order;
$orders[] = $order;
}
printf("Mem after: %.2f mb\n\n", memory_get_usage(true) / 1024 / 1024);
unset($orders, $i);
$orders = [];
printf("Test3\nMem before: %.2f mb\n", memory_get_usage(true) / 1024 / 1024);
for ( $i = 0; ++$i < 100000; )
{
$order = new Order;
$order->id = '123';
$order->number = '12345';
$order->date = '123456';
$orders[] = $order;
}
printf("Mem after: %.2f mb\n\n", memory_get_usage(true) / 1024 / 1024);
unset($orders, $i);
printf("Mem after: %.2f mb\n\n", memory_get_usage(true) / 1024 / 1024);
Expected result:
----------------
no memory leaks
Actual result:
--------------
PHP 5.4.17-1~dotdeb.0 Linux
Test1
Mem before: 0.25 mb
Mem after: 16.25 mb
Test2
Mem before: 4.75 mb
Mem after: 16.25 mb
Test3
Mem before: 5.00 mb
Mem after: 24.25 mb
Mem after: 5.25 mb
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65300&edit=1