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

refcount

Hi,

Is is possible to access the refcount for an object?

Ideally, I am looking to see if I have a refcount of 1 before calling del

Thanks

Simon

--
Linux Counter: User# 424693

Jan 29 '08 #1
1 2557
Simon Pickles <si*******@hotmail.comwrote:
Is is possible to access the refcount for an object?
>>import sys
sys.getrefcount(42)
6
Ideally, I am looking to see if I have a refcount of 1 before calling del
That's a pointless exercise: you probably don't understand what del does.

All that del does is remove one reference from an object, either by
removing a name from the namespace, or by removing a reference from
something like a list. 'del x' does NOT destroy the object referenced by x,
unless it happens that there are no other references to the object.

Also note that the only time you will see a reference count of 1 is on an
object which you cannot otherwise access (the only reference is being used
for the call to getrefcount()):
>>x = 99999
sys.getrefcount(x)
2
Jan 29 '08 #2

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

Similar topics

1
by: Ames Andreas (MPA/DF) | last post by:
Hi all, I'm currently building an extension module by hand and am confused by the fact that as well xxmodule.c as structmodule.c and other examples increment the refcount of the exception...
0
by: Jean-François Doyon | last post by:
Hello, I'm working with Zope 2.7 and Python 2.3.3, and I have some leaks I'm trying to track down. So, more generally, I'm wondering what might be good techniques to track down where...
4
by: Julie | last post by:
Does anyone know why the Finalize method (if present) isn't called immediately after the instance refcount is set to 0? It seems to me, that if it were, it would solve at least two issues: -...
3
by: Jens Theisen | last post by:
Hello, python uses gc only where refcounts alone haven't yet done the job. Thus, the following code class Foo: def __del__(self): print "deled!" def foo():
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
0
by: Gabriel Genellina | last post by:
Hi With Python 2.5, there is a change on the reference count of objects compared with previous versions (as reported by sys.getrefcount). All Python versions from 2.1 thru 2.4 gave these...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
0
by: paalkrebs | last post by:
I've made two smartpointers that I'd like to share. Improvements and comments are welcome. The key to both is that there should be no access to the managed object, and all operations should be...
2
by: Berthold =?iso-8859-15?Q?H=F6llmann?= | last post by:
I have a problem with my debug Python 2.5.2 executable with Py_REF_DEBUG and Py_TRACE_REFS set. With one of my scripts I get: .... Fatal Python error: Python/ceval.c:947 object at 0x2aa3f4d840...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.