INCREF DECREF manually

M

moerchendiser2k3

Hi,

just a small question. Is it possible to change the refcount of a
reference manually? For debugging / ...

Thanks!

moerchendiser2k3
 
J

Jean-Michel Pichavant

moerchendiser2k3 said:
Hi,

just a small question. Is it possible to change the refcount of a
reference manually? For debugging / ...

Thanks!

moerchendiser2k3
Why don't you just create a global reference to the object ? Unless this
one is removed, the object will be kept in memory.

JM
 
M

moerchendiser2k3

Do to some debugging if a version contains a bug and needs to be fixed
there manually.
 
A

Antoine Pitrou

Do to some debugging if a version contains a bug and needs to be fixed
there manually.

This is certainly the wrong approach.
To know if your Python code is leaking references, use either
sys.getrefcount(), or (better) a weakref -- and don't forget to
call gc.collect().
To know if some C extension is buggy, use your C debugger (or your
favourite alternative debugging method, such as printf()).

Changing reference counts from Python will lead to two possible
consequences:
- if you increment a reference count, you will have a permanent memory
leak
- if you decrement a reference count, you will eventually crash the
interpreter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

time_struct 2
buffer objects (C-API) 1
Simple (x,y) graph 3
C-API PyObject_Call 18
Simple lock 5
Problem with multiprocessing 0
Profiling: Interpreting tottime 3
Extract doc strings 5

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top