Beginner's question about reference counts...

Martin von Loewis loewis at informatik.hu-berlin.de
Thu Jul 13 05:03:49 EDT 2000


Miguel Marques <miguel at apex.ccs.yorku.ca> writes:

> I think I need to, because PyDict_SetItemString INCREFs both keys and
> values and otherwise the reference count for newdict will off by one?

Exactly, yes. Think of every reference in the counter being "owned" by
somebody. The d dictionary owns its own reference to d, and you keep
the reference given to you when the dictionary was created - so you
have to drop it when you don't need it anymore.

Regards,
Martin



More information about the Python-list mailing list