6

I am encoutering the following error with Symfony when trying to

php app/console cache:clear

or

php app/console cache:warmup

Fatal error: Allowed memory size of xxx bytes exhausted.

I already set memory limit to very large size 1024M, 2048M. I removed all twig templates from my project I unactivated vendors bundles leaving only FOSUSer and FOSRestBundle.

I am unable to track from where this error comes from.

Any idea?

Thanks

I get the following error

enter image description here

4
  • 3
    Try to run command with -vvv option: php app/console cache:clear -vvv. It will give you more information. Your problem located in some of your twig templates (yes, it is still here because you can see this error). I think that one of your templates have recursion problem. Try to find survived templates in the whole project folder. It can be located not only in Resources/views of your bundle folder but in app/Resources/views or in any other folder if you have non-standart directory structure. Commented Jan 9, 2016 at 17:51
  • Is your project on github? Perhaps someone could try it. I assume that you can bring down the standard edition and get it to work with no extra bundles at all. Commented Jan 9, 2016 at 18:26
  • Michael: The print screen is with -vvv. I'll double check any survived template :) So you also think it must be related to Twig with this message? Cerad I might do that if in a few hours I don't find it :p Commented Jan 9, 2016 at 19:40
  • @MichaelSivolobov your comment about the verbose option should be answer on its own. While it does not show how to fix Xavier13's problem, these issues with memory differ from user to user, and what is needed is a proper way to find the errors, which your comment addresses. It may qualify for an answer if you were to explain what to do after -vvv Commented Nov 18, 2016 at 9:29

3 Answers 3

7

In the end, it was that little piece of code that was the problem:

# config.yml
...   
twig:     
    paths:
            "%kernel.root_dir%": app

Thanks guys for confirming me that it was Twig the problem.

Sign up to request clarification or add additional context in comments.

3 Comments

Would you elaborate?
To elaborate for others, when using paths twig attempts to parse and compile the files in the specified URI, in the OP's case all files in %kernel.root_dir%. This can drastically increase compile times as all of the files in the paths are read. Not sure how the OP changed it to resolve their problem.
Probably, it's better to stick to the default Twig configuration: default_path: '%kernel.project_dir%/templates'. Still, in my case I had to allocate more memory in php.ini, memory_limit = 256M.
2

Try clearing the cache manually. Depending on the version of Symfony you're using, you can find the cache folder in either app/cache or var/cache. Try doing

rm -rf app/cache/* (or var if you're on Symfony3) and see if you still get the error.

3 Comments

Thank you. Already tried, once cache is manually emptied I get the same error just after.
Perhaps a certain vendor file got corrupted? Try doing a php composer.phar update and see if that can fix any of your vendor packages. The only other reason I can think of is that you have an infinite loop somewhere that's causing your PHP shell to run out of memory.
Deleted all vendors, reinstalled everything, without success. Desperating ^^
0

In my case, the problem was caused by a service making use of cache while it is being cleared.

Solution:

  • check that no service initializes its data from cache in constructor, the Symfony way is lazy load
  • make sure that no service circle references with another - as both are initialized, they may run out of memory trying to initialize recursively (An indirect recursion occurs, where A calls B, and B calls A, on init). But this is not workable anyway.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.