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

  • Home
  • SEARCH
  • 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 3758804
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:13:06+00:00 2026-05-19T10:13:06+00:00

Before you tell me to read the manual, check out the php.net documentation for

  • 0

Before you tell me to read the manual, check out the php.net documentation for this function:

Warning
This function is currently not documented; only its argument list is available.

That was helpful!

This page explains that it enables garbage collection for cyclic references. Where and when is this useful? Could someone show me an example of its use? Preferably an example where a cyclic reference is created and then collected.

  • 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-19T10:13:07+00:00Added an answer on May 19, 2026 at 10:13 am

    gc_enable is only needed if you call gc_disable. There is really no sane reason to do this, as that would cause cyclic references to not be garbage collected (like pre-5.3, when the cyclic GC did not exist).

    PHP’s garbage collector works by reference counting. You can think of a variable as a “pointer” to an object. When an object has no pointers to it, it is “dead” because nothing can reach it, so it is garbage collected.

    //one thing points to the Foo object
    $a = new Foo();
    
    //now two things do
    $b = $a;
    
    //now only $b points to it
    $a = null;
    
    //now nothing points to Foo, so php garbage collects the object
    $b = null;
    

    Consider this though:

    $a = new Foo();
    $b = new Bar();
    $b->foo = $a;
    $a->bar = $b;
    
    $a = $b = null;
    

    At this point nothing is holding on to $a or $b except the objects themselves. This is a cyclic reference, and in previous versions of php (< 5.3), would not be collected. The cyclic collector in 5.3 can now detect this and clean up these objects.

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

Sidebar

Related Questions

Before start let me tell my experience: I am experienced with C#.NET, web services,
Before you down vote this, let me say that I've read ALOT of questions
I'm running JBoss 4.2.3, Java 1.5, and Ubuntu. Before you tell me to post
Before you start flaming, I'm going to tell you that I am trying to
I did a search before asking so please don't tell me to do that.
Basically I would like to tell MSTest to execute a bit of code before
Before answering, it is not as easy question as you might have thought about
Before I begin I'll freely admit it's something in my code but it's not
Before I throw something ugly together I thought this would be a good one
Working with MonoTouch .NET for iPhone and SQLite on Mac OSX. I can read

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.