0

It seems to be differnt ways to call the helper or model classes.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$objectManager->create('Magento\Framework\Pricing\Helper\Data');

Or

protected $helper;
public function __construct(
    Magento\Framework\Pricing\Helper\Data as  $helper,
) {
    $this->helper = $helper;
}

I think second option is better one.

But is there any server load , memory usage or performance difference between two ?

1

Yes, there will be performance differences. The first method will be declared in the function of a block or modal, and it will be called and an instance will be created every time the function is called. This uses more resources and memory. Instead the second way will be declared in a constructor which will be called once minimizing the consumption of resources.

I'm not a master Magento guy, hope it helps......

|improve this answer|||||
0

Yes, Object manager should be used only in factories and then as injected in a controller. It take more memory than inject.

Note : for some reason we use object manager.

You should not use the Object Manager directly!

Exception from the rule are:

in static magic methods like __wakeup, serialize, etc in case you should make backward compatibility of constructor in global scope, like in fixtures of integration test. in class that needs only for creation of object like factory, proxy , etc

For more reference and Source :

Magento 2: to use or not to use the ObjectManager directly?

Magento 2 : what are the place use object manager. what are the place need to avoid?

http://devdocs.magento.com/guides/v2.0/extension-dev-guide/object-manager.html

|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.