Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6614387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:19:58+00:00 2026-05-25T20:19:58+00:00

Why does sys.getrefcount() return 3 for every large number or simple string?Does that mean

  • 0

Why does

sys.getrefcount() 

return 3 for every large number or simple string?Does that mean that 3 objects reside somewhere in the Program?Also,why doesn’t setting x=(very large number) increase that object’s ref count?Do those 3 ref counts result from my call to getrefcount?
Thank you for clarifying this.

for instance:

>>> sys.getrefcount(4234234555)
3
>>> sys.getrefcount("testing")
3
>>> sys.getrefcount(11111111111111111)
3
>>> x=11111111111111111
>>> sys.getrefcount(11111111111111111)
3 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:19:58+00:00Added an answer on May 25, 2026 at 8:19 pm

    Large integer objects are not reused by the interpretor, so you get two distinct objects:

    >>> a = 11111
    >>> b = 11111
    >>> id(a)
    40351656
    >>> id(b)
    40351704
    

    sys.getrefcount(11111) always returns the same number because it measures the reference count of a fresh object.

    For small integers, Python always reuses the same object:

    >>> sys.getrefcount(1)
    73
    

    Usually you would get only one reference to a new object:

    >>> sys.getrefcount(object())
    1
    

    But integers are allocated in a special pre-malloced area by Python for performance optimization, and I suspect the extra two references have something to do with this.

    It’s implemented in longobject.c in CPython. (Update: link to Python3.) I do not claim to understand what’s really going on. I think there are several things at work that cache temporary references:

    print sys.getrefcount('foo1111111111111' + 'bar1111111111111') #1
    print sys.getrefcount(111111111111 + 2222222222222)            #2
    print sys.getrefcount('foobar333333333333333333')              #3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that does various things and access parameters using sys.argv but
Today I ran against the fact, that sys.exit() called from a child-thread does not
Why does /cdrom has the same inode -number than /sys/devices/platform/power in Ubuntu? The following
>>> sys.getsizeof(int) 436 #? does this mean int occupies 436 bytes . >>> sys.getsizeof(1)
Does anybody know any good resources for learning how to program CIL with in-depth
Does anyone have any recommendations of tools that can be of assistance with moving
Does anyone use have a good regex library that they like to use? Most
Does anyone have a definitive answer to whether Sql Server Management Objects is compatible
all DLLs and EXEs in Symbian goes to sys\bin folder, right? does system DLLs
Where is my pythonpath stored? When I write import sys sys.path Where does Python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.