I am executing a program in PHP and getting the below error sometimes.Is this due to creating lot’s of objects and not destroying them or any other reason?
Allowed memory size of 16777216 bytes exhausted (tried to allocate 19456 bytes)
What is the correct method to destroy an object in PHP5.
Some code:
App::import('Vendor','GoogleShipping',array('file'=>'googlecheckout'.DS.'library'.DS.'googleshipping.php'));
App::import('Vendor','GoogleTax',array('file'=>'googlecheckout'.DS.'library'.DS.'googletax.php'));
class Cart{
var $_itemname;
var $_unit_price;
public function Usecase($itemname,$unit_price,$url,$merchant_private_item_data)
{
$cart = new GoogleCart($this->_merchant_id, $this->_merchant_key, $this->_server_type,$this->_currency);
$item_1 = new GoogleItem($this->_itemname,$this->_item_description,$this->_total_count,$this->_unit_price,$this->_merchant_private_item_data);
}
}
Without seeing the code, we can’t tell exactly what is causing this error. It could be creating too many objects, but it could just as easily be creating too big an array or other data.
Either way regardless of what type of data you’re creating that is throwing the error, it’s likely to be a loop or recursive function running out of control that’s the underlying cause, creating new data on every iteration, rather than you deliberately creating enough objects to overflow that much memory.
If you really do need to create enough data to fill that much memory then you can modify the maximum memory allowance in PHP.ini, but it’s unlikely.