我正在编写一个 magento 产品导出器,它将几个属性写入 csv 文件。一个属性称为“类别字符串”,其方法如下所示:
...
foreach($products as $_product) {
...
$productId = $_product->getSku();
$productCategory = getCategoryString($_product['category_ids']);
...
}
...
function getCategoryString($numbers) {
$catString = '';
$catModel = Mage::getModel('catalog/category')->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID);
$ex = explode(',', $numbers);
foreach ($ex as $i => $e) {
if ($i > 0) {
$catString .= $catModel->load($e)->getName();
if ($i < (count($ex)-1))
$catString .= ' > ';
}
}
$ex = NULL;
$numbers = NULL;
$catModel->unsetData();
unset($catModel);
$catModel = NULL;
return $catString;
}
但在每次迭代之后,每个产品的方法调用成本约为 1MB,而我有大约 9000 个产品!我无法清理 $catModel 变量!$catModel = NULL 和 unset($catModel) 行没有效果。我究竟做错了什么?我怎样才能强制取消设置对象?!