Tag: 终结者

Python3variables名称的简单区别可以改变代码的运行方式吗?

这个代码… class Person: num_of_people = 0 def __init__(self, name): self.name = name Person.num_of_people += 1 def __del__(self): Person.num_of_people -= 1 def __str__(self): return 'Hello, my name is ' + self.name cb = Person('Corey') kb = Person('Katie') v = Person('Val') 产生以下错误… Exception AttributeError: "'NoneType' object has no attribute 'num_of_people'" in <bound method Person.__del__ of <__main__.Person object […]

finalize()在Java 8中调用强可到达的对象

我们最近将我们的消息处理应用程序从Java 7升级到了Java 8.自从升级之后,我们偶然发现一个stream正在被读取时closures的exception。 日志logging显示终结器线程正在调用持有stream的对象的finalize() (它依次closuresstream)。 代码的基本概述如下: MIMEWriter writer = new MIMEWriter( out ); in = new InflaterInputStream( databaseBlobInputStream ); MIMEBodyPart attachmentPart = new MIMEBodyPart( in ); writer.writePart( attachmentPart ); MIMEWriter和MIMEBodyPart是本土MIME / HTTP库的一部分。 MIMEBodyPart扩展HTTPMessage ,它具有以下内容: public void close() throws IOException { if ( m_stream != null ) { m_stream.close(); } } protected void finalize() { try […]