Magento memory leak fix 1.4.x

A memory leak was found and identified in Mageto CE versions 1.4.x and has since been fixed in Magento CE versions 1.5.x. This should help speed up imports and inventory management, if you are currently using Community Edition 1.4.x.
Index: app/code/core/Mage/CatalogInventory/Model/Observer.php
===================================================================
--- app/code/core/Mage/CatalogInventory/Model/Observer.php (revision 88134)
+++ app/code/core/Mage/CatalogInventory/Model/Observer.php (working copy)
@@ -44,6 +44,14 @@
protected $_itemsForReindex = array();
/**
+ * Array, indexed by product's id to contain stockItems of already loaded products
+ * Some kind of singleton for product's stock item
+ *
+ * @var array
+ */
+ protected $_stockItemsArray = array();
+
+ /**
* Add stock information to product
*
* @param Varien_Event_Observer $observer
@@ -53,7 +61,12 @@
{
$product = $observer->getEvent()->getProduct();
if ($product instanceof Mage_Catalog_Model_Product) {
- Mage::getModel('cataloginventory/stock_item')->assignProduct($product);
+ $productId = intval($product->getId());
+ if (!isset($this->_stockItemsArray[$productId])) {
+ $this->_stockItemsArray[$productId] = Mage::getModel('cataloginventory/stock_item');
+ }
+ $productStockItem = $this->_stockItemsArray[$productId];
+ $productStockItem->assignProduct($product);
}
return $this;
}
Possibly Related Posts:
- Getting Started with Magento
- Magento vs X-Cart
- Magento version 2.0 (X.Commerce) and eBay
- Magento Supercharged Development Tools and Links
- Book Review: Magento 1.4 Themes Design by PacktLib
10Jan2011
3 Responses to Magento memory leak fix 1.4.x Add your comment
Leave a Reply
You must be logged in to post a comment.









Which version and what are the versions being compared in the diff file?
I believe it would be 1.4.x of the Community Edition.
Confirmed in 1.4.1.1 CE and the fix is applied in 1.5.0.0 alpha 2