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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:33:48+00:00 2026-05-11T03:33:48+00:00

If I am using a tree structure of nodes similar to the code below,

  • 0

If I am using a tree structure of nodes similar to the code below, do I have to worry about the circular reference?
I have read that PHP uses a memory allocation mechanism which can make life very hard for the garbage collector when there are circular references involved.

What I want to know is:

  • If my tree consists of only a few nodes, say 25, is this a problem?
  • Will the memory be freed at the end of the script or am I slowly creating a problem for the server?
  • Under what circumstances will this problem have an effect during script execution?
  • Will manually destroying the references solve the problem and should I always do it?
class Node {     private $parent;     private $children;      function addChild( Node $child ) {         $this->children[] = $child;         $child->setParent( $this );     }      function setParent( $parent ) {         $this->parent = $parent;     } }  //eg $node0 = new Node; $node1 = new Node;  // nodes 1 and 2 have a circular reference to each other $node0->addChild( $node1 ); 
  • 1 1 Answer
  • 3 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. 2026-05-11T03:33:49+00:00Added an answer on May 11, 2026 at 3:33 am

    Point by point:

    • If my tree consists of only a few nodes, say 25, is this a problem?

    Not unless your nodes are real monsters.

    • Will the memory be freed at the end of the script or am I slowly creating a problem for the server?

    When the interpreter shuts down all the memory is released.

    • Under what circumstances will this problem have an effect during script execution?

    I doubt you will have anything to worry about unless you have very low memory limits or very large dynamic data structures. If you have 25 nodes that aren’t being created/freed frequently you won’t have an issue.

    • Will manually destroying the references solve the problem and should I always do it?

    It will help. When loading a large data set into our database with Propel we ran into a lot of problem with memory consumption that we tracked to circular references not being freed. Our solution was to call a method that cleared all references.

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

Sidebar

Ask A Question

Stats

  • Questions 146k
  • Answers 146k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer task :default do setup task1 task2 end May 12, 2026 at 9:00 am
  • Editorial Team
    Editorial Team added an answer It also doesn't clutter your svn status list. But anyway,… May 12, 2026 at 9:00 am
  • Editorial Team
    Editorial Team added an answer Ajax requests happen asynchronously, so the execution of the Javascript… May 12, 2026 at 9:00 am

Related Questions

I am using a wxGenericDirCtrl, and I would like to know if there is
What is your preferred method of traversing a tree data structure, since recursive method
This is for MySQL and PHP I have a table that contains the following
I am implementing a tree think of it as a folder structure so I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.