Clearing Cache using CLI results in Fatal Error - alloed Memory exhausted

Hi Team @rcheesley
I would really like to understand why this is generating the errors on clearing the cache, there are 2 different files mentioned below.

If we need to tweak the clearing of the cache then understanding how would be great.
But solving this would be first class.

Suggestion and comments or links to existing ways to solve this would be appreciated
Matt

Your software
My Mautic version is: 6.0.1
My PHP version is: 8.2
My Database type and version is: mariadb

Your problem
My problem is: Error during CLI command clearing the cache.

These errors are showing in the log:

2025-05-07 08:25:07 - Clearing Mautic cache...

 // Clearing the cache for the prod environment with debug false                                                        

PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 122880 bytes) in /home/mautic-xxx/webapps/mautic/public/vendor/twig/twig/src/Compiler.php on line 146

In Compiler.php line 146:
                                                                                      
  Error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 122880 bytes)  
                                                                                            
cache:clear [--no-warmup] [--no-optional-warmers]

2025-05-07 08:25:44 - Clear Cache failed. Check logs or configurations.

[2025-05-07T08:38:37.569884+00:00] php.CRITICAL: Fatal Error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 73728 bytes) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\OutOfMemoryError(code: 0): Error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 73728 bytes) at /home/mautic-coolmusic/webapps/mautic-xxx/public/vendor/twig/twig/src/Loader/FilesystemLoader.php:133)"} {"hostname":"a-srv24-wwm-ubuntu24","pid":281990}

2025-05-07 08:37:56 - Clearing Mautic cache...

 // Clearing the cache for the prod environment with debug false                                                        

PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 73728 bytes) in /home/mautic-coolmusic/webapps/mautic-xxx/public/vendor/twig/twig/src/Loader/FilesystemLoader.php on line 133

In FilesystemLoader.php line 133:
                                                                                           
  Error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 73728 bytes)  
                                                                                           
cache:clear [--no-warmup] [--no-optional-warmers]

2025-05-07 08:38:37 - Clear Cache failed. Check logs or configurations.

This is a server config issue. You don’t have enough memory for the task to complete.

@rcheesley When you say this does not have enough memory… are we talking

  1. server wide
  2. per project
  3. what is the ideal

That error happened on a new install with no data.
We set the memory at 1024M
Is this enough ?

Matt