Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93165 > unrolled thread

Re: Reference Counting Irregularity

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2015-06-25 14:56 -0600
Last post2015-06-25 14:56 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Reference Counting Irregularity Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-25 14:56 -0600

#93165 — Re: Reference Counting Irregularity

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-06-25 14:56 -0600
SubjectRe: Reference Counting Irregularity
Message-ID<mailman.83.1435265856.3674.python-list@python.org>
On Thu, Jun 25, 2015 at 12:49 PM, Eric Edmond <t-erice@microsoft.com> wrote:
> Hi,
>
> I have been writing a C++ extension for Python recently, and am currently
> fixing the reference counting throughout the extension. As I am very new to
> this topic, my question may have a simple answer, but I was unable to find
> any mention of the behavior online.
>
> When using the PyObject_GetItem(obj, key) function, I noticed inconsistent
> behavior with various types of obj (for reference, key is always a str
> object). When obj is a standard dictionary, the key’s reference count
> remains unchanged, as expected. However, when obj is a pandas DataFrame
> object, the key’s reference count increases by 2. This could very well be by
> design of the DataFrame object doing some internal caching of the string,
> but does not appear in the documentation, so I thought I would bring up the
> issue.

What is your question? If you want to know why 2 is added to the
reference count for pandas objects, the first place to check would be
with the pandas developers, as PyObject_GetItem is just going to call
the implementation for that type. You can find the CPython code here:

https://hg.python.org/cpython/file/9aad116baee8/Objects/abstract.c#l136

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web