Haseeb Ahmad
Haseeb Ahmad

Reputation: 8730

Allowed memory size of 100663296 bytes exhausted (tried to allocate 32 bytes)

Using with command in yii give memory error.When I use 3 tables it works fine. As I add 4th then it starts give an error on server. Locally it works fine

$criteria->with = array('users0','businessUnits','skills','questions');
$criteria->together = true;

$models = Company::model()->findAll($criteria);

It gives an error Allowed memory size of 100663296 bytes exhausted (tried to allocate 32 bytes) in

Upvotes: 0

Views: 2243

Answers (1)

Avinash Sinha
Avinash Sinha

Reputation: 424

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.

Upvotes: 1

Related Questions