22

I can find lots of tutorials on how to overcome the out-of-memory error. The solution is: To increase the memory in the php.ini or in the .htaccess - what a surprise...

I actually don't understand the error message:

Fatal error: Out of memory (allocated 32016932) (tried to allocate 25152 bytes)

"Allocated 32016932", means 32MB have been allocated as in - the PHP script is using 32MB? Tried to allocate 25152, means that another 25KB were tried to be allocated, but the script failed as the maximum (of ~ 32MB?) has been reached?

What can I actually tell from this error message, besides that I'm "out of memory"?

4
  • 1
    Usually if you get this it's indicative of an infinite loop somewhere in your code. Commented Feb 25, 2011 at 15:19
  • It really isn't about solving the error - I know I'm getting the error due to trying to work on a 3MB JPG - too much for my shared hosting account - I just want to understand the error ;-) Commented Feb 25, 2011 at 15:37
  • I don't think it's at all fair to say it indicates an infinite loop. An infinite loop is one of an infinite number of ways that you can use up more memory than PHP has been allotted. Commented Jan 26, 2012 at 18:28
  • No, it is not always an infinite loop. I get it many times when trying to upload large files or working with those serverside in a PHP script (e.g. modules/extensions in CMS systems). Not always an infinite loop but rather a restriction of the hosting system. Commented Jan 26, 2012 at 20:08

2 Answers 2

16

I Always interpreted it like:

Fatal error: Out of memory ([currently] allocated 32016932) (tried to allocate [additional] 25152 bytes)

But good Question if there is a bulletproof explanation.

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

6 Comments

@MatejB you are right, but as far as I understood the Question is what you can get from that message, and unfortunately, that is all there is to get
@MatejB and bad People ;) [looking in your direction] .... nah I think it is a perfectly valid Question, I myself think the error message could be a little bit more clear, especially when I started with PHP way back I remember it confusing me more then one time. The matter about how to track and deal with memory leaks is, well, a whole another matter
@MatejB well, not my call, but i guess it still counts as "further reading" ?;)
except that it often gives vastly different allocated xxxxxxxx values, on the same server, and same setup, intermittently.
@NoBugs yes, as long as the currently allocated + the additional allocated is larger then the allowed memory it will fail. Really depends on what the application is doing at any given moment. Also all kinds of things you might not be aware of can influence this value. For example the varying size of external resources loaded by php ( cache from apc, dataset from db ) ect.
|
8

It's exactly like you understood it.

The limit is probably set at 32MB, you have already 32016932 bytes allocated and when php tried to allocate 25152 more bytes, the limit is exceeded thus the error message.

You probably can see the line where the faulty allocation happened in your logs or near the error message on your screen.

Good luck finding the culprit.

1 Comment

I like this answer. I would also add to it that the additional allocation is not indicative of what PHP may have needed to complete said operation, but what was being asked for over the limit at the time of the crash.

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.