top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between Mage::getModel() and Mage::getSingletone() in Magento?

0 votes
487 views
What is the difference between Mage::getModel() and Mage::getSingletone() in Magento?
posted Feb 24, 2018 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Mage::getSingleton()

Mage::getSingleton() will first check the same class instance is exits or not in memory. If the instance is created then it will return the same object from memory.

$product1 = Mage::getSingleton('catalog/product');
$product2 = Mage::getSingleton('catalog/product');

$product1 and $product2 both will share same memory of OS and return only one instance each time.

Mage::getgetModel()

Mage::getModel() will create a new instance of an object each time even such object exists in configuration.

$product1 = Mage::getModel('catalog/product');
$product2 = Mage::getModel('catalog/product');

$product1 and $product2 both have different instant of same object and also occupy different memory .

answer Feb 24, 2018 by Vishi Gulati
...