I do a simple loop over all products (within a cron) to generate a block and cache the results,
but the toHhtml method lets memory_get_usage() grow to about 0.1M per product
I can reduce the effect for load of getModel but toHTML kills it
foreach($products as $productid) {
// leaks but clear instance helps
$model = Mage::getModel("catalog/product")->load($productid);
$block1 = Mage::app()->getLayout()->createBlock("catalog/product_list_upsell");
$block1 = $block1->setTemplate("catalog/product/list/upsell.phtml");
// kills it
cacheContent($block1->toHTml());
// this helps
$model->clearInstance();
}
any idea, except processing each loop item in a separate php call ?
You don’t need to create a new block instance every time. The data gets prepared on every call to
toHtml(), just create$block1once and reuse it.This should remove a lot of references to model instances that won’t be needed anymore.
Edit: That being said, did you leave out the code where you register the product instance for blocks? It should be:
}