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 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

Related Questions

I have an arbitrary tree structure of nodes. I want to draw this tree
In C# I have an intrusive tree structure that looks like this: public abstract
I have a tree structure in MySQL using a parent_id field for each node.
Is there a way to find all nodes in a xml tree using cElementTree?
I have tree control object created using CTreeCtrl MFC class. The tree control needs
I have an expression tree I have created by parsing an Xml using the
I am writing some UI tests using Selenium and i have a JavaScript Tree
I'm recently working on a tree structure, multiple nodes, multiple and increasable levels, and
I have a basic tree structure of entities. The tree can be a maximum
I am using jsTree to display a tree structure of hierarchical data within my

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.