title: How unique is Python's id()?
body: <p><strong>tl;dr</strong>
  Does Python reuse ids? How likely it is that two objects with non overlapping lifetime will get the same id?</p>
  
  <p><strong>Background:</strong>
  I've been working on a complex project, written purely in Python 3. I've been seeing some issues in testing and spent a lot of time searching for a root cause. After some analysis, my suspicion was that when the testing is being run as a whole (it's orchestrated and being run by a dedicated dispatcher) it's reusing some mocked methods instead of instatiating new objects with their original methods. To check if the interpreter is reusing I used <code>id()</code>.</p>
  
  <p><strong>Problem:</strong>
  <code>id()</code> usually works and shows the object identifier and lets me tell when my call is creating a new instance and not reusing. But what happens when ids if two objects are the same? <a href="https://docs.python.org/3/library/functions.html#id" rel="noreferrer">The documentation</a> says:</p>
  
  <blockquote>
    <p>Return the “identity” of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same <code>id()</code> value.</p>
  </blockquote>
  
  <p><strong>The questions:</strong></p>
  
  <ol>
  <li><p>When can the interpreter reuse <code>id()</code> values? Is it just when it randomly selects the same memory area? If it's just random, it seems extremely unlikely but it's still not guaranteed.</p></li>
  <li><p>Is there any other method to check what object I am actually referencing? I encountered a situation where I had the object, it had a mocked method. The object was no longer used, garbage collector destroyed it. After that I create a new object of the same class, it got a new <code>id()</code> but the method got the same id as when it was mocked and it actually <em>was</em> just a mock.</p></li>
  <li><p>Is there a way to force Python to destroy the given object instance? From the reading I did it appears that no and that it is up to a garbage collector when it sees no references to the object but I thought it's worth asking anyway.</p></li>
  </ol>