5 Replies - 230 Views - Last Post: 19 June 2013 - 11:19 AM Rate Topic: -----

#1 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Memory Leaks

Posted 19 June 2013 - 10:48 AM

Hi all,

I've been working on a large group of PHP scripts, and suddenly none of them will run anymore at all. I looked in my error_log file and found this error:

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 2887680 bytes) in myFile.php on line LINE



I've worked with PHP before, and this is the first time I've run into memeory leaks -- I feel like a newbie; I didn't even know PHP could have memory leaks! It's an interesting learning experience, to be sure, but it's kind of putting a crimp in my development -- since I can't run any scripts now, I can't continue developing.

Does anyone know how to clear the PHP memory that is allocated? Also, is there an easy way to unallocate all objects created across scripts during a session? I thought using session_unset and session_destroy would work, but apparently they don't do that.

If anyone could give me some pointers here (haha, pointers, appropriate for a memory leak question :) ), I'd really appreciate it.

Thanks,
Zel2008

Is This A Good Question/Topic? 0
  • +

Replies To: Memory Leaks

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9098
  • View blog
  • Posts: 34,181
  • Joined: 12-June 08

Re: Memory Leaks

Posted 19 June 2013 - 10:58 AM

Perhaps explore the joys of garbage collection?

http://php.net/manua...features.gc.php
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2959
  • View blog
  • Posts: 10,183
  • Joined: 08-August 08

Re: Memory Leaks

Posted 19 June 2013 - 11:04 AM

PHP arrays are not declared as a fixed size in advance, so they can grow to fill all available memory. Maybe you've got an infinite loop adding elements to an array?
Was This Post Helpful? 2
  • +
  • -

#4 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Re: Memory Leaks

Posted 19 June 2013 - 11:06 AM

Thanks modl,

This definitely looks like what I need to do, but the manual doesn't seem to be very helpful -- all I got is that PHP has garbage collection, but not how it relates to destructors, unsetting, or the best way to do so. I guess I have a new thing to Google, though, maybe I can try that. Do you know of any other good examples that might help me wrap my head around this?

Thanks,
Zel2008
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9098
  • View blog
  • Posts: 34,181
  • Joined: 12-June 08

Re: Memory Leaks

Posted 19 June 2013 - 11:11 AM

As you said - a cursory google search of "how to use php garbage collection" pulls up some interesting articles. ;)

http://www.tuxradar....icalphp/18/1/10
http://www.tuxradar....icalphp/18/1/11
http://phpmaster.com...age-collection/

Of course CTphpnwb could be totally right. Without seeing your code St. Christopher knows we are just throwing hatchets in in the dark.
Was This Post Helpful? 1
  • +
  • -

#6 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Re: Memory Leaks

Posted 19 June 2013 - 11:19 AM

Thanks modl and CT,
I'll see what I can do; thanks for the resources.
Zel2008
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1