From: Lawrence D'Oliveiro on 21 Apr 2010 20:53 In message <4bc9aadb$1(a)dnews.tpgi.com.au>, Lie Ryan wrote: > Since in python nothing is guaranteed about implicit file close ... It is guaranteed that objects with a reference count of zero will be disposed. In my experiments, this happens immediately.
From: Chris Rebert on 21 Apr 2010 21:03 On Wed, Apr 21, 2010 at 5:53 PM, Lawrence D'Oliveiro wrote: > In message <4bc9aadb$1(a)dnews.tpgi.com.au>, Lie Ryan wrote: > >> Since in python nothing is guaranteed about implicit file close ... > > It is guaranteed that objects with a reference count of zero will be > disposed. > In my experiments, this happens immediately. Experiment with an implementation other than CPython and prepare to be surprised. Cheers, Chris -- http://blog.rebertia.com
From: Alf P. Steinbach on 24 Apr 2010 03:30 * Steven D'Aprano: > On Fri, 23 Apr 2010 13:19:41 +0200, Alf P. Steinbach wrote: > >> But for a literal context-free interpretation e.g. the 'sys.getrefcount' >> function is not documented as CPython only and thus an implementation >> that didn't do reference counting would not be a conforming Python >> implementation. > > Since Jython and IronPython are conforming Python implementations, and > Guido has started making policy decisions specifically to support these > other implementations (e.g. the language feature moratorium, PEP 3003), I > think we can assume that this is a documentation bug. The documentation for Jython specifies the same for 'sys.getrefcount'. However, testing: <output> *sys-package-mgr*: processing new jar, 'C:\Program Files\jython2.5.1\jython.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\resources.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\rt.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\jsse.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\jce.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\charsets.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\dnsns.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\localedata.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\sunjce_provider.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\sunmscapi.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\sunpkcs11.jar' A created Traceback (most recent call last): File "c:\test\refcount.py", line 17, in <module> writeln( str( sys.getrefcount( a ) - 1 ) ) AttributeError: 'systemstate' object has no attribute 'getrefcount' </output> > However, a Python implementation that always returned 0 for > sys.getrefcount would technically satisfy the word of the documentation, > if not the spirit. Yes. OK, learned something new: I though Jython actually implemented getrefcount. The Jython docs says it does... Cheers, - Alf
From: Lawrence D'Oliveiro on 27 Apr 2010 06:06
In message <mailman.2162.1272018097.23598.python-list(a)python.org>, Adam Tauno Williams wrote: > On Fri, 2010-04-23 at 16:29 +1200, Lawrence D'Oliveiro wrote: > >> Any implementation that doesn't do reference-counting is brain-damaged. > > Why? Because a) it uses extra memory needlessly, and b) waiting until an object has dropped out of cache before touching it again just slows things down. > There are much better ways to do memory management / garbage > collection; especially when dealing with large applications. Especially with large applications, the above considerations apply even more so. If you don't agree, you might as well stick to Java. |