Hey guys. I am working on a PHP project using Zend Framework and I am trying to track the bloated memory issues I am running into.
Long story short, I am making a business application that has an opportunity, each opportunity can have multiple quotes, each quote can have multiple items, each item has a product. Each product can have many other parameters.
As I step through the code, outputting memory, it seems as though the objects themselves are not too bad, but memory gets absolutely abused when I first create an object of any type.
For example, $product=new application_model_product_item(); $product->load($sku);
will increase the memory usage by 1 MB. Which is insane.
But if I clear out that object using a custom $product->clear(); function and then unset($product); I only gain back like 100kb. And, if I do
$product=new application_model_product_item(); $product->load($sku);
$product2=new application_model_product_item(); $product2->load($sku2);
my memory footprint only increases by 1.1MB. So its like the object itself is only 100kb, but the act of creating the first product uses a meg. I believe this may be due to the zend auto-loader. But I dont know for sure.
This would not be the end of the world. It sucks, but thats the biggest class, and if it takes up 1MB one time, then all other objects of it take up .1, I could deal.
But whats strange is, as I go through a quote, looping through each of its items, creating a product for each of those items has a footprint of 1MB. But creating TWO products for each of those items only costs 1.1MB. For some reason, creating that first product for each item is an entire meg.
This persists throughout. Components of the product each have a much larger footprint when first created, but subsequent objects of that class do not.
I can not figure out the leak. Ive gone through all the children and grand children, trying to tackle what is causing it, and each time, each child takes up a lot of memory when it is first created, but then it doesnt seem to actually use much as an object.
Basically it seems like
if parent one creates child one, tons of memory is used. But it does not use much to create child two.
But then if parent two creates child one, tons of memory is used again, but it does not use much to create child two.
I can not for the life of me figure this out. I am not doing anything that should require a ton of memory, I am simply loading data from a DB and storing the information in data model objects. But they are absolutely bloated.