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 8174707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:31:51+00:00 2026-06-06T22:31:51+00:00

Do I need to worry about memory leaks with PHP? In particular, I have

  • 0

Do I need to worry about memory leaks with PHP? In particular, I have the following code that is being called from a browser. When the call finishes, is everything cleaned up properly, or, do I need to clear the memory created by the first array that was created?

class SomeClass
{
  var $someArray = array();

  function someMethod()
  {
     $this->someArray[1] = "Some Value 1";
     $this->someArray[2] = "Some Value 2";
     $this->someArray[3] = "Some Value 3";
     $this->someArray = array();
     $this->someArray[1] = "Some other Value";
     $this->someArray[2] = "Some other Value";
     $this->someArray[3] = "Some other Value";
  }
}

someMethod();

Thanks,
Scott

  • 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-06-06T22:31:52+00:00Added an answer on June 6, 2026 at 10:31 pm

    Do I need to worry about memory leaks with PHP?

    It’s possible to have a cyclic reference in PHP where the refcount of the zval never drops to 0. This will cause a memory leak (GC won’t clean up objects that have a reference to them). This has been fixed in >= PHP 5.3.

    In particular, I have the following code that is being called from a browser. When the call finishes, is everything cleaned up properly, or, do I need to clear the memory created by the first array that was created?

    PHP scripts have a request lifecycle (run application, return response, close application), so it shouldn’t be a worry. All memory used by your application should be marked as free’d when your application finishes, ready to be overwritten on the next request.

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

Sidebar

Related Questions

Please assume that I do not need to worry about development time and costs:
I have a PHP program that reads from the database and generated formatted sheets.
I've been told to not worry about retain counts. I understand that I shouldn't
I have some large MySQL production tables that I need to dump so that
I have a situation where I need to store a globally unique identifier that
I am checking my program against memory leaks and corruptions and I have a
Do I need to worry about performance in the case below and save the
In the new Try-with-Resources syntax in Java 7 do I need to worry about
What are some situations where you need to worry about whether a static method
Do I need to worry about managing the size of html5 localStorage, or will

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.