Ucodice Technologies
Ucodice Technologies Pvt. Ltd.
Ucodice Technologies Pvt. Ltd.
Ucodice Technologies Pvt. Ltd.

Fatal error Allowed memory size of 33554432 bytes exhausted

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)

 

Ucodice Technologies
Ucodice Technologies Pvt. Ltd.
Ucodice Technologies Pvt. Ltd.
Ucodice Technologies Pvt. Ltd.
Menu

Comments

Please share your views with us

Check if you want to display your email-id.

Let's collaborate

write to us

contact@ucodice.com

Contact Form