title: Are dynamically created classes destroyed just like other objects are?
body: <p>To preface this, this is a hypothetical, and just a question that popped into my head while I was prototyping some code. Dynamically creating classes has a pretty narrow range of applicable usages.</p>
  
  <p>In Python, I can dynamically define a class by, for example, nesting its definition inside a def[1]:</p>
  
  <pre><code>def NewClass(doc):
    class MyClass(object):
      __doc__ = doc
    return MyClass
  </code></pre>
  
  <p>What happens when the instance of the class becomes unused? Does its refcount go to zero and is it destroyed just like other objects? Or is it handled a little bit specially because its a class? Reading the language docs, I didn't see much anything about class object destruction.</p>
  
  <p>More specifically, if I had code creating these in response to user requests, e.g., so there were thousands or millions being created through the lifetime of a process, would I need to worry about running out of memory because of all the created classes?</p>
  
  <p>[1] e.g., the <code>type</code> "function", and probably various meta-class things or <code>__new__</code> tricks.</p>