Skip to main content

Magento 2: Allowed memory size exhausted

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

Jackson
  • 10k
  • 31
  • 131
  • 217