Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in Magento customer Create

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in Magento customer Create

August 17, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in Magento customer Create

Fatal Error: Magento Customer Creation Memory Exhaustion Issue

Are you facing a memory exhaustion error while creating customers in your Magento 2 store? Let’s dive into this common issue and explore practical solutions to resolve it.

The Issue at Hand

You’re likely encountering the following fatal error when trying to create a new customer:

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes)
in /vendor/magento/framework/Model/ResourceModel/Db/VersionControl/Snapshot.php on line 47

You’ve already increased the memory limit to a hefty 8 GB, but the issue persists. The culprit seems to be located in this specific line of code:

$data = array_merge($metaData, $filteredData);

Found within the Snapshot.php file from the Magento framework’s resource model.

Understanding the Root Cause

This error occurs due to excessive memory usage during the customer creation process. The array_merge() function attempts to combine two large arrays ($metaData and $filteredData), which can exceed the allocated memory limit if either of these arrays is excessively large.

The issue arises when creating a new customer, as Magento attempts to track changes in entity data for version control purposes. However, the process becomes inefficient and consumes too much RAM, leading to this fatal error.

Practical Solutions

  1. Optimize Version Control Magento’s version control system can be resource-intensive by default. Consider disabling it during customer creation to reduce memory usage temporarily. You can do this using the following configuration:

    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
        <default scope="default" id="versioning_config">
            <enabled>0</enabled>
        </default>
    </config>
    

    Save this in your app/code/Magento/Versioning/etc/config.xml or create the file if it doesn’t exist.

  2. Update Your Code If you have access to the core Magento codebase (not recommended for production sites), consider updating the problematic line of code:

    $data = array_intersect_key($metaData, $filteredData);
    

    The array_diff() function is more memory-efficient than array_merge(). However, this change should be thoroughly tested in a development environment before applying it to your live site.

  3. Increase Memory Limit Temporarily You can temporarily increase the PHP memory limit during customer creation using Magento’s event listeners and observers. This approach ensures that you only allocate extra resources when necessary:

    public function afterCreate(Observer $observer)
    {
        ini_set('memory_limit', '2G'); // Increase to 2GB for this specific process
    }
    

    Save this code in your custom module’s etc/events.xml file, and map it to the appropriate event (e.g., customer_create_after).

Best Practices

  1. Regular Maintenance: Keep your Magento store up-to-date with the latest security patches and performance optimizations.
  2. Caching: Enable caching mechanisms like Varnish or Redis to reduce server load.
  3. Optimize Images: Compress product images and thumbnails to minimize storage requirements.

Conclusion

Resolving this memory exhaustion issue requires a combination of configuration tweaks, code optimization, and careful management of Magento’s version control system. Remember that increasing the PHP memory limit should be considered a temporary workaround rather than a permanent solution.

For comprehensive guidance on Magento performance optimizations, check out our detailed guide at https://laravelcompany.com/magento-performance-optimization-guide.

Magento 2 Performance Customers SEO

Our network