On 9/27/07, Robert Bradshaw <[EMAIL PROTECTED]> wrote: > You have a good point, though fortunately we're looking for refcounts > so low that (essentially) nothing else can be holding onto it but the > current stack frame. If b is pointing to a, it doesn't matter how > many other things are (directly or indirectly). If nothing is > pointing to it directly, it's difficult (but not impossible) for > things to safely point to it indirectly. Also, we would only play > this trick with SAGE elements, which we have more control over.
The subtlety appears if the object you're dealing with is itself a view of something else: In [3]: a = N.arange(10) In [4]: b = a[::2] In [5]: sys.getrefcount(b) Out[5]: 2 In [6]: sys.getrefcount(a) Out[6]: 3 In [7]: c = a[::2] In [8]: sys.getrefcount(b) Out[8]: 2 In [9]: c.fill(999) In [10]: sys.getrefcount(b) Out[10]: 2 In [11]: b Out[11]: array([999, 999, 999, 999, 999]) In this case, b gets modified indirectly, even though its refcount never went above 2, so it would appear 'safe' by a refcounting argument. The problem is that b is itself a view onto another object (a) for which someone else (c) is holding also 'write access'. So while b appears to be 'isolated', it is still in reality subject to modification. Cheers, f --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---