[Fixed]: Allowed Memory Size of Bytes Exhausted Magento 2

[Fixed]: Allowed Memory Size of Bytes Exhausted Magento 2
Magento 2 users sometimes encounter the error “allowed memory size of xxxx size exhausted” when installing a Magento 2 theme, extension or executing compile/deploy command. Fatal error: allowed memory size of xxxxx bytes exhausted (tried to allocate xxxx bytes)

Cause of the Error:

The cause of the error “allowed memory size of bytes exhausted” is obvious i.e. it’s related to shortage of memory. The error occurs if you try to use more RAM resources than what you have specified in the php.ini file through “memory_limit”.

Solution:

Remember, out of memory errors are one of the most common and hard to fix. In this case, however, the solution is simple. You just have to increase the memory limit in the php.ini file. It is the default configuration file that is used to control upload sizes, file timeouts and resource limits. This is what you have to do to resolve the error.
  • Locate php.ini file. This will usually be etc/php.ini.
  • Find the parameter memory_limt =128M
  • Increase the limit to 256M or 512M.

Increase the Memory Limit

You can also increase the memory limit using the following commands.
php -d memory_limit=1G bin/magento setup:di:compile
php -d memory_limit=1G bin/magento setup:static-content:deploy

You can change 1G to whatever limit you want. This will surely resolve the error allowed memory size of bytes exhausted in Magento 2.

That’s all for this article. This is as straightforward as it seems. However, no question is a wrong question so don’t hesitate to contact us in case you have any questions related to this article.