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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:53:16+00:00 2026-06-18T02:53:16+00:00

In this example: class Foo(object): def __del__(self): print Foo died class Bar(object): def __init__(self):

  • 0

In this example:

class Foo(object):
    def __del__(self):
        print "Foo died"

class Bar(object):
    def __init__(self):
        self.foo = Foo()
        self.baz = Baz(self)

class Baz(object):
    def __init__(self, bar):
        self.bar = bar

b = Bar()

I’d expect the Foo destructor to be called in spite of the loop between Bar and Baz, as since Foo holds no references to any bar or baz collecting them and decrementing reference counts should be completely safe to do before collecting Foo. Why doesn’t python behave this way? How can destructors possibly be useful if they can be prevented from being called by completely unrelated actions of other classes?

  • 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-18T02:53:18+00:00Added an answer on June 18, 2026 at 2:53 am

    Note that the destructor does not need to be called when the interpreter exits.

    A quick modification to your script and all works as you expected:

    class Foo(object):
        def __del__(self):
            print "Foo died"
    
    class Bar(object):
        def __init__(self):
            self.foo = Foo()
            self.baz = Baz(self)
    
    class Baz(object):
        def __init__(self, bar):
            self.bar = bar
    
    b = Bar()
    
    del b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given is the following example: class Foo(object): def __init__(self, value=0): self.value=value def __int__(self): return
For example, suppose I have the code: class Foo(object): def bar(self, x): '''blah blah
I have the following example code: class A(object): def __init__(self, id): self.myid = id
I am having trouble mocking an injected object. For example: class Foo def initialize(bar
This is just an example, but given the following model: class Foo(models.model): bar =
Given an arbitrary object: class Val(object): def __init__(self): this_val = 123 I want to
the next is my code: class foo: def __init__(self): self.a = a def __getattr__(self,x,defalut):
I'm using SharedPreferences to persists Object fields. Take this example: class Item { private
Consider this example: #include <iostream> class myclass { public: void print() { std::cout <<
In Ruby, I can do this: module Foo end class Bar include Foo end

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.