<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/python-find-all-instances-of-a-class-with-gc-get-objects--ls4pvl1jd" -->

---
title: Python: find all instances of a class with gc.get_objects()
description: A practical debugging technique using Python's `gc.get_objects()` to find all live instances of a given class at runtime, without modifying the class itself....
canonical: https://daily.dev/posts/python-find-all-instances-of-a-class-with-gc-get-objects--ls4pvl1jd
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Python: find all instances of a class with gc.get_objects() | daily.dev
og:description: A practical debugging technique using Python's `gc.get_objects()` to find all live instances of a given class at runtime, without modifying the class itself....
og:url: https://daily.dev/posts/python-find-all-instances-of-a-class-with-gc-get-objects--ls4pvl1jd
og:image: https://api.daily.dev/og/posts/Ls4pVl1JD.png
og:image:alt: Python: find all instances of a class with gc.get_objects()
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Python: find all instances of a class with gc.get_objects()

**[Adam Johnson](https://daily.dev/sources/adamj)** · 2 min read · 0 upvotes · 0 comments

## Summary

A practical debugging technique using Python's `gc.get_objects()` to find all live instances of a given class at runtime, without modifying the class itself. The approach uses a list comprehension with `isinstance()` to filter objects tracked by the garbage collector. Caveats include performance (traverses all live objects) and keeping references alive — addressed by deleting the list or using a generator expression instead.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://adamj.eu/tech/2026/07/14/python-all-instances-class>

## Similar posts on daily.dev

- [Everything You Need to Know About How Python Manages Memory](https://daily.dev/posts/everything-you-need-to-know-about-how-python-manages-memory-nxob1tkgz) · Machine Learning Mastery · 0 upvotes · 0 comments
- [zpoint/CPython-Internals: Dive into CPython internals, trying to illustrate every detail of CPython implementation](https://daily.dev/posts/zpoint-cpython-internals-dive-into-cpython-internals-trying-to-illustrate-every-detail-of-cpython--35zlnbmaw) · Hacker News · 0 upvotes · 0 comments
- [Python Numbers Every Programmer Should Know](https://daily.dev/posts/python-numbers-every-programmer-should-know-dbwyosyik) · Planet Python · 4 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python)

[View this post on daily.dev](https://daily.dev/posts/python-find-all-instances-of-a-class-with-gc-get-objects--ls4pvl1jd)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Python: find all instances of a class with gc.get_objects()","url":"https://daily.dev/posts/python-find-all-instances-of-a-class-with-gc-get-objects--ls4pvl1jd","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/python-find-all-instances-of-a-class-with-gc-get-objects--ls4pvl1jd"},"datePublished":"2026-07-14T20:12:09.488Z","dateModified":"2026-07-14T20:36:38.051Z","description":"A practical debugging technique using Python's `gc.get_objects()` to find all live instances of a given class at runtime, without modifying the class itself....","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/27e90bb6b07e0130d5035b6dec7e6ab3?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/27e90bb6b07e0130d5035b6dec7e6ab3?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Adam Johnson","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Adam Johnson","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/bf70f4401c284aa5b628d1966029342c","url":"https://daily.dev/sources/adamj"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/python-find-all-instances-of-a-class-with-gc-get-objects--ls4pvl1jd","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Adam Johnson","item":"https://daily.dev/sources/adamj"},{"@type":"ListItem","position":3,"name":"Python: find all instances of a class with gc.get_objects()"}]}
```

