Problem - Fatal error: Allowed memory size of 33554432 bytes exhausted
Reason for Fatal error: Allowed memory size of X bytes exhausted
Recently I have encountered this error with one of my php application. Like any other programmer I thought of googling the issue.
After some research I came to find that for some reason my script is taking all the memory space. As I was on shared hosting & ini_set was disabled by the server admin.
I had no other option than finding the root cause of the issue.
Incorrect Solution : Solutions such as increase the memory is not the correct solution. By that you are allowing your bad script to consume all the memory.
So how to solve the issue?
Suppose you are creating a variable that is carrying so much data. In loop you are reassigning value to that.
So you reassign too much data to a same variable, though its values are getting updated but memory is not getting freed yet as variable is in use & garbage collector is not clearing that memory.
Correct Solution : To avoid Allowed memory size exhausted error you can set the value to null. By doing so you are telling garbage collector whatever kept in memory for that variable is not required & freed. Garbage collect will immediately clear the space.
By: Ankush Negi
(Software Engineer @ Ucodice)