PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 36 bytes) in {snip}/CLASSES/CompDB.inc on line 1202
Does anyone know of a function that retuens the amout of memory used by PHP, so I can try to isolate where I'm loosing memory? There is no reason for my script to be using that much space...
Variables are automatically garbage-collected when they are no longer reachable, correct?
Sigh, it was a very stupid error on my part. A counter wasn't getting reset so a loop was repeating endlessly, tacking on an empty table cell to a string on every pass. The string got bigger than memory before the script execution time limit was hit.
I'm not use to memory bugs actually occuring where the program crashes, normally its due to something much earlier in the program.
That's not a memory leak in the classic sense. I guess it is in the sense that you don't know where memory is going. However, notice that the error says that you reached the limit of "Allowed" memory, which by the way can be adjusted upwards in the php.ini file. This is really a logic issue.
Was also thinking that perhaps it's possible to parse the output of something like free, top, or ps if you are using Linux. At that rate, it's may be possible to see what your script is doing. If there are any native functions that can do this, I don't know about them.
True its not a classic memory leak, but when a script goes from using a few hundred k to 8 MB its a little disturbing. And yes it was a logic error. Raising the allowed memory was my first thought, but of course it wouldn't have solved anything, except maybe changing the out of memory error to a time out error.
I was really wondering if there was some un-documented top/free-like built in, which it appears there isn't.