473,386 Members | 1,908 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,386 software developers and data experts.

getting the reference count of an object ...

.... how?

I'm writing an app that holds a public data dictionary from which other
objects obtain part of their __dict__ values so they all work on the
same dataset (yes I'm fiendishly clever and a constructor of unreadable
sentences (and code) ;)).

My problem is that I haven't found an easy way to determine if said
dictionary contents are still in use (so it is ok to delete them from
the dictionary). I've thought about creating a dict subclass that counts
the number of assignments and deletions but that seems cumbersome (an
bug-prone).

Is there a way to get the reference count of these datadict items? I
imagine that this would be a more stable implementation of such a feature.

Hope this gets my problem accross; if not just bash me and I'll
reformulate. I'm not the best of explainers.

Oh, and sorry if the solution to my problem is obvious (such as an
__refcount__ attribute or some stupid oversight like that).

c.u.
wildemar
Mar 3 '06 #1
1 2046
In article <ma***************************************@python. org>,
Wildemar Wildenburger <wi******@freakmail.de> wrote:
... how?

I'm writing an app that holds a public data dictionary from which other
objects obtain part of their __dict__ values so they all work on the
same dataset (yes I'm fiendishly clever and a constructor of unreadable
sentences (and code) ;)).

My problem is that I haven't found an easy way to determine if said
dictionary contents are still in use (so it is ok to delete them from
the dictionary). I've thought about creating a dict subclass that counts
the number of assignments and deletions but that seems cumbersome (an
bug-prone).

Is there a way to get the reference count of these datadict items? I
imagine that this would be a more stable implementation of such a feature.

Hope this gets my problem accross; if not just bash me and I'll
reformulate. I'm not the best of explainers.

Oh, and sorry if the solution to my problem is obvious (such as an
__refcount__ attribute or some stupid oversight like that).


Direct answer: sys.getrefcount()

Better answer: look at the weakref module, especially at the various
Dict helper classes.

Just
Mar 3 '06 #2

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

Similar topics

0
by: Kalle Rutanen | last post by:
Hello I implemented reference counting in my program, and found out many problems associated with it. I wonder if the following problems can be solved automatically rather manually ? 1. ...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage...
3
by: Poewood | last post by:
Okay here are four classes for a pocket pc program: Input, fpositional, ComboBoxArray and TextBoxArray. The "input" class is the form. I use the fpositional class to handle most of the functions...
12
by: Bill O | last post by:
Is there a way to determine the number of references to an object? I only need a reference count. Thank you, Bill
5
by: raghu | last post by:
Hi All, I am a new user of Python and am having a bit of problem understanding the Reference counting and memory leakage issues. Requesting help from experienced users.... I wrote the...
1
by: ank | last post by:
Hi, all. I've come to think of the idea of automatic initialization/deinitialization of non-local reference count pointer. I've made an assumption that the user of the pointer only read...
2
by: ank | last post by:
Hi, all. I've come to think of the idea of automatic initialization/deinitialization of non-local reference count pointer. I've made an assumption that the user of the pointer only read...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
jinu1996
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 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.