My objects eats too much (and weird!) memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello!

I'm new here, so I do not know if attachments are allowed, so I put my
code below.

I've written this to check memory consumption of PHP5 objects, because
I'm having memory problems with an OO XMLParser that I've written.

When I execute the code from cli, I get:



$ php MemTest.php
Obj1 uses 208 bytes
Obj2 uses 168 bytes
Obj3 uses 200 bytes
Obj4 uses 200 bytes
Obj5 uses 200 bytes
Obj6 uses 200 bytes


I understand that first instance may be bigger than next ones because
method allocation and other things of that kind, but I do not understand
why second instance is smaller than third :-?

So, my first question is: Why third object is a 16% smaller than third
and nexts?

In any case, my second question is: Isn't too much memory 200 bytes for
a so simply object??


And the third: Is there any manner to get more compact objects in PHP5?


Thanks a lot in advance.

-------
<?php

class dummy {
	protected $a;

	public function __construct ( $a ) {
		$this->a = $a;
	}
}

$before=0;
$memdiff=0;

$before = memory_get_usage();
$obj1 = new dummy (0);
$memdiff = memory_get_usage()-$before;
echo "Obj1 uses $memdiff bytes\n";

$before = memory_get_usage();
$obj2 = new dummy (0);
$memdiff = memory_get_usage()-$before;
echo "Obj2 uses $memdiff bytes\n";

$before = memory_get_usage();
$obj3 = new dummy (0);
$memdiff = memory_get_usage()-$before;
echo "Obj3 uses $memdiff bytes\n";

$before = memory_get_usage();
$obj4 = new dummy (0);
$memdiff = memory_get_usage()-$before;
echo "Obj4 uses $memdiff bytes\n";

$before = memory_get_usage();
$obj5 = new dummy (0);
$memdiff = memory_get_usage()-$before;
echo "Obj5 uses $memdiff bytes\n";

$before = memory_get_usage();
$obj6 = new dummy (0);
$memdiff = memory_get_usage()-$before;
echo "Obj6 uses $memdiff bytes\n";


?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux