Issue1851

classification
Title: weakrefs broken
Type: behaviour Severity: major
Components: Library Versions: 2.5.2
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: fwierzbicki Nosy List: danilo2, fwierzbicki
Priority: Keywords:

Created on 2012-03-15.15:18:59 by danilo2, last changed 2012-03-15.16:04:36 by fwierzbicki.

Messages
msg6797 (view) Author: danilo2 (danilo2) Date: 2012-03-15.15:18:59
Hi! 
weakrefs in juthon 2.5.2 does not work as they should. concider this code from jython manual:
import weakref
class Object:
    pass
o = Object()
r = weakref.ref(o)
o2 = r()
o is o2
del o, o2
print '!'
print r()

as a reusult we can see "<_main_.Object instance at 0x15434>" not None
msg6798 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2012-03-15.16:04:36
Hi danilo2,

Looking at weakref at http://docs.python.org/library/weakref.html you'll note the paragraph:

A weak reference to an object is not enough to keep the object alive: when the only remaining references to a referent are weak references, garbage collection is free to destroy the referent and reuse its memory for something else.

Of particular note is "garbage collection is free to destroy..."

So even though the current implementation of CPython appears to destroy the weakref in a deterministic fashion, that will be due to it's reference counted gc implementation. Jython does not have deterministic garbage collection and so will not immediately destroy the weakref. In fact the time of destruction is in no way guaranteed.
History
Date User Action Args
2012-03-15 16:04:36fwierzbickisetstatus: open -> closed
assignee: fwierzbicki
resolution: invalid
messages: + msg6798
nosy: + fwierzbicki
2012-03-15 15:18:59danilo2create