1

Something very strange started happening yesterday while coding.

I was testing a new function, all was going fine. No issues. Was building json object and print_r on screen each time to check the successful building of the object in a testing method.

As I was implementing it into the codebase, again it was still working fine. I then went off to change a different method, updated code to work with that new method and tested it's related screens and all worked fine still.

Then all of a sudden on page reload (after seeing everything work fine), I'm getting a PHP memory leak error.

Fatal error: Allowed memory size of 1342177280 bytes exhausted (tried to allocate 65488 bytes) in D:\public_html\genesis\system\core\Common.php on line 901

This happens no matter what I isolate.

I've even converted the index page to:

public function index() {
        echo 'Hello World';
    //$this->buildPage("login");    
}

and it still throws the error.

I currently have the this for my memory limit:

memory_limit=2480M

It was at 1280, then I added another 1200 and still no difference.

My other sites are loading fine, just this one. But I can't seem to troubleshoot it at all cause I can't get ANY methods to load.

Has anyone else had this issue?

Any ideas on how to figure it out?

Solvision
  • 193
  • 1
  • 11
  • Generally this type of occurs when your script is using too much memory. This can often happen in PHP if you have a loop that has run out of control and you are creating objects or adding to arrays on each pass of the loop. **Check for infinite loops**. If that isn't the problem, try and help out PHP by destroying objects that you are finished with by setting them to null eg. $OldVar = null;. – Linus Mar 22 '16 at 21:26
  • Destroying old objects? Something like this? function ($oldObj) { $newObj = new stdClass(); $newObj->val1 = $oldObj-valX; $oldObj = null; return $newObj; } – Solvision Mar 22 '16 at 21:41
  • something like http://stackoverflow.com/questions/8798443/best-way-to-destroy-php-object – Linus Mar 22 '16 at 21:43

1 Answers1

3

OK so I figure it out, here is what I did and what was happening.

1) First I had to get xDebug installed. (https://xdebug.org/wizard.php)

2) Then I could see the errors when trying to load the page.

I had reached an maximum allowed nesting limit in Codeigniter. This was due to loading models within models and back again. I didn't realise cross model usage was not allowed.

So I moved my class based construct loading of primary models to the autoload.php file.

This got things loading again.

Solvision
  • 193
  • 1
  • 11
  • 2
    yeah you have done!! `but remember Never upgrad memory_limit variable on your php.ini file, or by setting up ini_set('memory_limit', 'XXXM'); on your PHP file that you are running, being XXX the amount of Mb memory that you want to define.Letting application to eat memory he wants to is insane step` – Linus Mar 22 '16 at 21:48