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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:19:42+00:00 2026-06-06T10:19:42+00:00

How crucial is object destruction in PHP? is it important to destroy objects in

  • 0

How crucial is object destruction in PHP? is it important to destroy objects in PHP after using them? because unlike java, PHP doesn’t have a garbage collector (nothing that I know of)

  • 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-06T10:19:45+00:00Added an answer on June 6, 2026 at 10:19 am

    You don’t need to destroy objects in the general case, and PHP certainly does have a garbage collector. Moreover, most simple scripts would not even really need one because the whole environment is torn down and rebuilt for every HTTP request; the garbage collector helps those scripts that would run out of memory while serving a single request.

    Exceptions to the general case:

    You might want to “lose” all references to objects that consume a large amount of memory and/or wrap unmanaged resources; this is usually as easy as

    $largeObject = null; // reference to previous value lost
    

    If that was the last reference to $largeObject, then:

    • PHP will immediately call the destructor (if one exists); you might want to do for objects which are wrapping unmanaged resources (e.g. database connections, sockets, etc) if your script is long-lived.
    • The memory that the object takes up will now be eligible for garbage collection. However, collection will not occur on the spot but at some later point where more memory is required (although you can call gc_collect_cycles to force garbage collection at any time).

    Of course all of this does not come into consideration in the typical case of “service a request and then exit”.

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

Sidebar

Related Questions

In my domain I have objects that are constantly being updated by a separate
I'm building a guestlist app for my company using PHP, Javascript/jQuery/Ajax, JSON and localstorage.
I have a situation where I have 2 Activity objects (let's say empty and
I have the following situation (simplified): a.h: #include <boost/serialisation/serialisation.hpp> class B; using namespace std;
I am designing a class... there are crucial methods that need an object passed
I have defined a subinterface of java.util.Collection that effectively is a multiset (aka bag).
We had a Nullable object must have a value error today on this line
In my android game I want to have a rhythm Mediaplayer object and a
EDIT: I missed a crucial point: .NET 2.0 Consider the case where I have
We are considering node.js as a web platform. But I have one crucial question,

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.