Magento – Magento 2: Allowed memory size exhausted

magento2performancePHP

I'm running my custom script on Magento 2. It gives below error.

PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /home/magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /home/magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93
PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /home/magento/vendor/magento/framework/Session/SessionManager.php on line 139
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /home/magento/vendor/magento/framework/Session/SessionManager.php on line 139

Do I need to set

ini_set('memory_limit', '6G');

?

On the start of script or need to change in php.ini

Best Answer

Change the setting in php.ini and restart server. There is no need to change in code or put in start of file because best solution is to do in php.ini.

You can also try in .htaccess.

Comment if face issue again. I will help you to sort out.