Path: csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'cpython': 0.05; 'counting': 0.07; 'objects,': 0.07; 'expected.': 0.09; 'extension.': 0.09; 'key)': 0.09; 'obj': 0.09; 'question?': 0.09; 'developers,': 0.10; 'python': 0.11; 'thu,': 0.15; 'caching': 0.16; 'dictionary,': 0.16; 'object).': 0.16; 'unchanged,': 0.16; 'wrote:': 0.16; 'string,': 0.18; 'extension': 0.20; 'issue.': 0.20; 'fixing': 0.22; 'function,': 0.22; '2015': 0.23; 'header:In- Reply-To:1': 0.24; 'question': 0.26; 'object,': 0.27; 'message- id:@mail.gmail.com': 0.28; 'noticed': 0.29; 'appear': 0.29; 'str': 0.29; 'mention': 0.31; 'code': 0.31; 'url:python': 0.33; '(for': 0.34; 'throughout': 0.34; 'received:google.com': 0.34; 'could': 0.35; 'to:addr:python-list': 0.35; 'c++': 0.35; 'eric': 0.35; 'but': 0.36; 'url:org': 0.36; 'hi,': 0.37; 'subject:: ': 0.37; 'thought': 0.37; 'skip:p 20': 0.38; 'doing': 0.38; 'pm,': 0.39; 'does': 0.39; 'unable': 0.39; 'to:addr:python.org': 0.39; 'why': 0.40; 'some': 0.40; 'your': 0.60; 'behavior': 0.61; 'bring': 0.61; 'simple': 0.61; 'here:': 0.62; 'topic,': 0.79; 'subject:Reference': 0.84; 'to:name:python': 0.84; 'url:cpython': 0.84; 'increases': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=AYD5iQvf7Wa9gZO/BdBNn30oYb4Nh0Eizd9Pkmwn650=; b=HDY6YcsOI8Y0a6lgJ/AbVCGAz2QTaPFR/4n7bvKw7jNVUxNYO0QkIfSX9eKoKVAsMO bXa4cHx9BUc3G/O8F8oMedGqlNLbkpEEnOiljl57eQXqjB8mYDqXn0XA6Sw6odLpmtQ5 NnBs0CT1UM1g95V6Kv6igWNnXjwS0iiafQ1nEYzMasbFZfECn3t7U6Xa823XzE7VR5WS sMoh5VEui0xor6Rz7TWgtv3zpnlgf37DN42zqm2m8aJw7oxng3BCgQpBWvwXQ9yEOYaC KTOhn+w6xWS5rFI+iSlQY1GX+Iasdw/hM2ws+zgXsYdIZx20I9d9HQvQELnGAL35hPef f5cA== X-Received: by 10.170.141.4 with SMTP id i4mr21315935ykc.32.1435265853924; Thu, 25 Jun 2015 13:57:33 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Thu, 25 Jun 2015 14:56:54 -0600 Subject: Re: Reference Counting Irregularity To: Python Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435265856 news.xs4all.nl 2938 [2001:888:2000:d::a6]:56430 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93165 On Thu, Jun 25, 2015 at 12:49 PM, Eric Edmond 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 fin= d > any mention of the behavior online. > > When using the PyObject_GetItem(obj, key) function, I noticed inconsisten= t > behavior with various types of obj (for reference, key is always a str > object). When obj is a standard dictionary, the key=E2=80=99s reference c= ount > remains unchanged, as expected. However, when obj is a pandas DataFrame > object, the key=E2=80=99s 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 t= he > 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