Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6724605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:42:34+00:00 2026-05-26T09:42:34+00:00

A colleague of mine wrote a script that was exhausting the available memory. I

  • 0

A colleague of mine wrote a script that was exhausting the available memory. I narrowed it down to the following basic test case:

for ( $i = 0; $i <= 20; $i ++ ) {
    echo memory_get_usage(). '<br />';
    $Survey = new Survey( 14 );
    echo memory_get_usage(). '<br /><br />';
}
exit('done');

This breaks on the third iteration:

3116696
49123440

49123440
95518368

95518368
[E_ERROR] Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes)

I managed to fix this, by simply adding an unset() call in the loop:

for ( $i = 0; $i <= 20; $i ++ ) {
    echo memory_get_usage(). '<br />';
    $Survey = new Survey( 14 );
    unset( $Survey );
    echo memory_get_usage(). '<br /><br />';
}
exit('done');

Now the script goes through its 20 iterations nice and smooth, with a relatively constant memory usage:

3116816
49123488

49123488
50691656

50691656
51088912

51088912
51079064

51079064
50535368

50535368
50809296

50809296
51033392

51033392
51157208

51157208
50543856

50543856
50892760

50892760
51045160

51045160
51132688

51132688
50535968

50535968
50968632

50968632
51058080

51058080
51143304

51143304
50562136

50562136
51067432

51067432
51067768

51067768
51170824

51170824
50551712

done

This confuses me! Isn’t the garbage collector supposed to clean up the object, as it’s variable has been overwritten? I’m running PHP 5.3, so circular references can’t be the cause of this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:42:35+00:00Added an answer on May 26, 2026 at 9:42 am

    Circular references can still be a problem in 5.3:

    Cleanup Problems

    Although there is no longer a symbol in any scope pointing to this
    structure, it cannot be cleaned up because the array element “1” still
    points to this same array. Because there is no external symbol
    pointing to it, there is no way for a user to clean up this structure;
    thus you get a memory leak. Fortunately, PHP will clean up this data
    structure at the end of the request, but before then, this is taking
    up valuable space in memory. This situation happens often if you’re
    implementing parsing algorithms or other things where you have a child
    point back at a “parent” element. The same situation can also happen
    with objects of course, where it actually is more likely to occur, as
    objects are always implicitly used by reference.

    There is probably also some memory-hogging resource inside Survey that takes up all of this memory; the observed behavior should be a combination of a ref cycle and such a resource.

    What’s in Survey exactly?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

a colleague of mine wrote a webservice that runs on port 8081 of our
A colleague of mine is looking for a method in System.IO that will do
A colleague of mine told me that I should never use static variables because
I have a problem that has just come up with a colleague of mine
A colleague of mine says that SQL Server saves the date and time of
A colleague of mine has issues with his VPN connection. It seems that his
A colleague of mine is attempting to consume a web service that has been
A colleague of mine needs to develop an Eclipse plugin that has to parse
A colleague of mine states that booleans as method arguments are not acceptable .
the other day a colleague of mine stated that using static classes can cause

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.