Home » Interview Question » Difference between Mage::getModel() and Mage::getSingleton() in magento

Difference between Mage::getModel() and Mage::getSingleton() in magento

Difference between Mage::getModel() and Mage::getSingleton() in magento

Mage::getSingleton() : Mage:getSingleton() will first check the same class instance is exits or not in memory, if the object for same class is already exit,then it will return the same object from the memory.

Mage:getSingleton() and Mage::getModel() define in Magento Root directory\app\Mage.php

calling the class object

 

Mage::getModel() :

Mage::getModel() is used when you want to get the fresh data from the database. Example: when you want to get records from database.

The difference between Mage:getSingleton() and Mage::getModel() is that, Mage:getSingleton() will first check the same class instance is exits or not in memory, if the object for same class is already exit,then it will return the same object from the memory. while Mage::getModel() creates new objects every time for the class when it’s class is called.

Example: Mage:getSingleton()

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

Example : Mage::getModel()

$product1 and $product2 both use different instant of same object and also occupy different memory in OS.

 

, , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">