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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:41:44+00:00 2026-05-31T17:41:44+00:00

Say I have a binary tree which contains pointers at each node going to

  • 0

Say I have a binary tree which contains pointers at each node going to the parent and the child, and I want to remove some part of an internal subtree, patching the remainder of the tree back together in a sensible way.

Does Python know to garbage collect the discarded piece of the subtree, even though the nodes within reference each other? I would expect this to be a capability of all languages which use garbage collection, but I don’t know enough about garbage collection to know for sure. The best I have done myself is a smart (C++) pointer system which was not smart enough to handle the case I described above.

  • 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-31T17:41:45+00:00Added an answer on May 31, 2026 at 5:41 pm

    Yes, Python will discard the unreferenced nodes in the tree.

    CPython uses reference counting to do most of is garbage collection. In your case, one or more of the tree nodes will have no references left, so they will be freed. Then the nodes that were pointed to by the freed node may have no references, and those will be freed too. Recursively, all unreferenced nodes will be freed.

    CPython also has a garbage collector that can collect unreferenced cycles. These can’t (easily) be detected using reference counting, but the cycle collector can identify and free them.

    Other implementations of Python such as IronPython or Jython use different garbage collector schemes.

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

Sidebar

Related Questions

Lets say I have the binary number 0b110, which is 6, and I want
Lets say I have some binary value: 0b100 and want to convert it to
Say I have a binary file of 12GB and I want to slice 8GB
Say, i have binary protocol, where first 4 bits represent a numeric value which
Let's say I have a binary tree data structure defined as follows type 'a
Let's say we have an SDK in C++ that accepts some binary data (like
Suppose I have a binary search tree which, initially, satisfies all of the red-black
Say I have a module which will get eventually some day on CPAN. Is
Let's say you have a List<List<Boolean>> and you want to encode that into binary
Let's say we have a binary file that contains 2 bytes that form an

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.