擅长:python、mysql、java
<blockquote>
<p>If no instances of the class are currently live, might the class and its class attributes be garbage-collected, and then created anew when the class is next used?</p>
</blockquote>
<p>不,已经被垃圾回收的类不存在“下一次使用”的情况,因为垃圾回收的唯一方法是如果没有办法使用它。在</p>
<blockquote>
<p>Suppose I create an instance of <code>C</code>, append 5 to <code>C.l</code>, and then that instance of <code>C</code> is no longer referenced and can be garbage-collected. Later, I create another instance of <code>C</code> and read the value of <code>C.l</code>. Am I guaranteed <code>C.l</code> will hold <code>[5]</code>?</p>
</blockquote>
<p>是的。该类有一个活动引用,因为您创建了另一个实例,而该列表将一个活动引用作为类的属性。在</p>
<blockquote>
<p>Does a class attribute have the same lifetime as a global variable?</p>
</blockquote>
<p>如果类包含对某个对象的引用,则该类的生存期至少与该类相同。在</p>