Reference count

Gary Herron gherron at islandtraining.com
Mon Aug 11 15:47:02 EDT 2003


On Monday 11 August 2003 12:30 pm, Pablo Yabo wrote:
> Hi,
> I need to keep a object alive even if its reference count if zero.
> Is there any way to increment its reference count using Python code, not
> Py_INCREF or there is any way to avoid deletion of the object?
>
> Thanks, in advance
>
> Pablo Yabo

Sure.  Just put the object into a list of things you want to keep
alive.  The the reference count will not be zero and the object will
not be garbage collected.

KeepAlive = []  # A global 

and somwhere in your code:
  KeepAlive.append(ImportantObject)

Gary Herron







More information about the Python-list mailing list