473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need help to understand garbage collection

I would need help to understand how garbage collection work and how to
"trace" objects...
In the example below an object is created and deleted.
Why in the second part of the example I do not see any object removed:

import gc
class Test(object):
def __init__(self):
original_objects_id = [id(x) for x in gc.get_objects()]
#create object a
a = Test()
new_objects = [x for x in gc.get_objects()
if id(x) not in original_objects_id]
print "-" * 40
print "Added object:", len(new_objects)
for obj in new_objects:
print "*" * 10
print str(id(obj)) + ":" + str(obj)
print gc.get_referents(obj)
print "*" * 3
print "-" * 20

original_objects_id = [id(x) for x in gc.get_objects()]
#remove object a
del a
after_rm_objects_id = [id(x) for x in gc.get_objects()]
removed_objects_id = [x for x in original_objects_id
if x not in after_rm_objects_id]
print "-" * 40
print "Removed objects:", len(removed_objects_id)
print removed_objects_id
print "-" * 20

Which give:

Added object: 2
400600:[[...], <__main__.Test object at 0x62bd0>]
[<__main__.Test object at 0x62bd0>, [[...], <__main__.Test object at 0x62bd0>]]
404432:<__main__.Test object at 0x62bd0>
[<class '__main__.Test'>]
Removed objects: 0
Oct 6 '07 #1
0 756

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Andrew | last post by:
When will .NET have a low-pause-time garbage collector A low-pause-time garbage collector would greatly improve .NET's ability to serve as a platform for soft real-time systems. It doesn't have...
by: Ganesh | last post by:
Is there a utility by microsoft (or anyone) to force garbage collection in a process without have access to the process code. regards Ganesh
by: Oculus | last post by:
Before I get into the question -- I know .NET isn't the right solution for this app but it's part of my clients requirements and writing this in C++ isn't an option. That being said -- my app is a...
by: Rick | last post by:
Hi, My question is.. if Lisp, a 40 year old language supports garbage collection, why didn't the authors of C++ choose garbage collection for this language? Are there fundamental reasons behind...
by: pachanga | last post by:
The Hans-Boehm garbage collector can be successfully used with C and C++, but not yet a standard for C++.. Is there talks about Garbage Collector to become in the C++ standard?
by: Chris | last post by:
Hi, I think I'm having some problems here with garbage collection. Currently, I have the following code: public struct Event { public int timestamp;
by: mike2036 | last post by:
For some reason it appears that garbage collection is releasing an object that I'm still using. The object is declared in a module and instantiated within a class that is in turn instantiated by...
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use...
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.