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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:07:46+00:00 2026-06-17T20:07:46+00:00

Edit: Generalised the question due to NPE’s comment. In a Python 2.7.3 interactive session:

  • 0

Edit: Generalised the question due to NPE’s comment.

In a Python 2.7.3 interactive session:

>>> class Foo(object):
...     pass
... 
>>> type("Bar", (Foo,), {})
<class '__main__.Bar'>
>>> Foo.__subclasses__()
[<class '__main__.Bar'>]
>>> 

Also:

>>> class Foo(object):
...     pass
... 
>>> class Bar(Foo):
...     pass
... 
>>> Foo.__subclasses__()
[<class '__main__.Bar'>]
>>> del Bar
>>> Foo.__subclasses__()
[<class '__main__.Bar'>]

How come Bar is still available via the __subclasses__ function? I would have expected it to be garbage collected.

Conversely, if I want it to be garbage collected, how do I do it?

  • 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-17T20:07:47+00:00Added an answer on June 17, 2026 at 8:07 pm

    See this thread. It would seem that what happens is the class’s __mro__ attribute stores a reference to itself, creating a reference cycle. You can force a full gc run which will detect the cycle and delete the object:

    >>> class Foo(object): pass
    >>> class Bar(Foo): pass
    >>> import gc
    >>> del Bar
    >>> gc.collect()
    3
    >>> Foo.__subclasses__()
    []
    

    Alternatively, if you enter other commands for a while, the gc will run on its own and collect the cycle.

    Note that you have to be a bit careful when testing this interactively, because the interactive interpreter stores a reference to the most recently returned value in the “last value” variable _. If you explicitly look at the subclass list and then immediately try to collect, it won’t work, because the _ variable will hold a list with a strong reference to the class.

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

Sidebar

Related Questions

EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
Edit (updated question) I have a simple C program: // it is not important
EDIT: Simple version of the question: I want to create server variables in the
Edit : updating generalized question to reflect actual domain: sport of hockey. The actual
EDIT : See Solving "Who owns the Zebra" programmatically? for a similar class of
[Edit] My original-question was Why to decide between static and non-static? Both do the
I recently generalized a type class away from a constraint MonadError GenError m to
//EDIT... I'm editing my question slightly to address the issue of working specifically with
EDIT: I was an idiot. I simply had an image that was vertically long,
EDIT: See my answer below--> I am wanting to have a view that when

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.