garbage collection / reference cycles (cont.)

Aaron Brady castironpi at gmail.com
Sun Mar 29 09:14:34 CEST 2009


On Mar 25, 12:12 am, Aaron Brady <castiro... at gmail.com> wrote:
> On Mar 25, 12:11 am, Aaron Brady <castiro... at gmail.com> wrote:
> > Hello,
>
> > I am posting the code I mentioned on Saturday that collects garbage
> > and cyclic garbage in a flattened two-step process.  The code takes
> > 122 lines incl. comments, with 100 in tests.  It should be in a reply
> > to this.
snip

Here is the output.  Someone suggested I add it.  It may or may not be
utterly unintelligible.  It's quite long, 367 lines.

>>> run( 'psu' ) # external references to 'p', 's', and 'u'

<q,4> decref
parents {<r,2>: {(<q,3>, 'at2')}, <p,3>: {(<q,3>, 'at')}, <q
,3>: {(<p,3>, 'at'), (<r,2>, 'at'), (<q,3>, 'at1')}, <t,3>:
{(<q,3>, 'at3')}}
refct_copy {<q,3>: 0, <r,2>: 1, <p,3>: 2, <t,3>: 2}
<r,2> decref
parents {<q,3>: {(<p,3>, 'at'), (<r,1>, 'at'), (<q,3>, 'at1'
)}, <r,1>: {(<q,3>, 'at2')}, <p,3>: {(<q,3>, 'at')}, <t,3>:
{(<q,3>, 'at3')}}
refct_copy {<r,1>: 0, <q,3>: 0, <p,3>: 2, <t,3>: 2}
<t,3> decref
parents {}
refct_copy {<t,2>: 2}
p: (q), q: (pqrt), r: (q), s: (p), t: (), u: (t)
>>>
>>> p.decref() # decref 'p'.  should not free any.
<p,3> decref
parents {<q,3>: {(<r,1>, 'at'), (<p,2>, 'at'), (<q,3>, 'at1'
)}, <r,1>: {(<q,3>, 'at2')}, <p,2>: {(<q,3>, 'at')}, <t,2>:
{(<q,3>, 'at3')}}
refct_copy {<p,2>: 1, <q,3>: 0, <r,1>: 0, <t,2>: 1}
>>>
>>> assert_exist( p, q, r, s, t, u )
<p,2> exists
<q,3> exists
<r,1> exists
<s,1> exists
<t,2> exists
<u,1> exists
>>>
>>> run( 'psu' ) # start over

<q,4> decref
parents {<r,2>: {(<q,3>, 'at2')}, <p,3>: {(<q,3>, 'at')}, <t
,3>: {(<q,3>, 'at3')}, <q,3>: {(<p,3>, 'at'), (<r,2>, 'at'),
 (<q,3>, 'at1')}}
refct_copy {<q,3>: 0, <r,2>: 1, <p,3>: 2, <t,3>: 2}
<r,2> decref
parents {<q,3>: {(<p,3>, 'at'), (<r,1>, 'at'), (<q,3>, 'at1'
)}, <r,1>: {(<q,3>, 'at2')}, <p,3>: {(<q,3>, 'at')}, <t,3>:
{(<q,3>, 'at3')}}
refct_copy {<r,1>: 0, <q,3>: 0, <p,3>: 2, <t,3>: 2}
<t,3> decref
parents {}
refct_copy {<t,2>: 2}
p: (q), q: (pqrt), r: (q), s: (p), t: (), u: (t)
>>>
>>> p.decref()
<p,3> decref
parents {<q,3>: {(<r,1>, 'at'), (<p,2>, 'at'), (<q,3>, 'at1'
)}, <r,1>: {(<q,3>, 'at2')}, <p,2>: {(<q,3>, 'at')}, <t,2>:
{(<q,3>, 'at3')}}
refct_copy {<p,2>: 1, <q,3>: 0, <t,2>: 1, <r,1>: 0}
>>>
>>> s.decref() # decref 'p' and 's'.  should decref 'q', 'r'
,
<s,1> decref
<p,2> decref
finalizing <s,0>
parents {<q,3>: {(<r,1>, 'at'), (<p,1>, 'at'), (<q,3>, 'at1'
)}, <r,1>: {(<q,3>, 'at2')}, <p,1>: {(<q,3>, 'at')}, <t,2>:
{(<q,3>, 'at3')}}
refct_copy {<p,1>: 0, <q,3>: 0, <t,2>: 1, <r,1>: 0}
cycle of <p,1> found
<q,3> decref
parents {<r,1>: {(<q,2>, 'at2')}, <p,1>: {(<q,2>, 'at')}, <t
,2>: {(<q,2>, 'at3')}, <q,2>: {(<r,1>, 'at'), (<q,2>, 'at1')
}}
refct_copy {<q,2>: 0, <r,1>: 0, <p,1>: 0, <t,2>: 1}
cycle of <q,2> found
<r,1> decref
<p,1> decref
<q,2> decref
<t,2> decref
finalizing <p,0>
<q,1> decref
finalizing <r,0>
finalizing <q,0>
parents {}
refct_copy {<t,1>: 1}
>>>            # and 't'.  should finalize 's', 'p', 'r', 'q
'.
...
>>> assert_exist( t, u )
<t,1> exists
<u,1> exists
>>> assert_destroyed( p, q, r, s )
<p,0> destroyed
<q,0> destroyed
<r,0> destroyed
<s,0> destroyed
>>>
>>> run( 'psu' )

<q,4> decref
parents {<r,2>: {(<q,3>, 'at2')}, <p,3>: {(<q,3>, 'at')}, <q
,3>: {(<p,3>, 'at'), (<r,2>, 'at'), (<q,3>, 'at1')}, <t,3>:
{(<q,3>, 'at3')}}
refct_copy {<q,3>: 0, <r,2>: 1, <t,3>: 2, <p,3>: 2}
<r,2> decref
parents {<q,3>: {(<p,3>, 'at'), (<r,1>, 'at'), (<q,3>, 'at1'
)}, <r,1>: {(<q,3>, 'at2')}, <t,3>: {(<q,3>, 'at3')}, <p,3>:
 {(<q,3>, 'at')}}
refct_copy {<r,1>: 0, <q,3>: 0, <t,3>: 2, <p,3>: 2}
<t,3> decref
parents {}
refct_copy {<t,2>: 2}
p: (q), q: (pqrt), r: (q), s: (p), t: (), u: (t)
>>>
>>> s.decref()
<s,1> decref
<p,3> decref
finalizing <s,0>
parents {<q,3>: {(<r,1>, 'at'), (<p,2>, 'at'), (<q,3>, 'at1'
)}, <r,1>: {(<q,3>, 'at2')}, <t,2>: {(<q,3>, 'at3')}, <p,2>:
 {(<q,3>, 'at')}}
refct_copy {<p,2>: 1, <q,3>: 0, <r,1>: 0, <t,2>: 1}
>>>
>>> p.decref() # same result, different order
<p,2> decref
parents {<q,3>: {(<r,1>, 'at'), (<p,1>, 'at'), (<q,3>, 'at1'
)}, <r,1>: {(<q,3>, 'at2')}, <t,2>: {(<q,3>, 'at3')}, <p,1>:
 {(<q,3>, 'at')}}
refct_copy {<p,1>: 0, <q,3>: 0, <r,1>: 0, <t,2>: 1}
cycle of <p,1> found
<q,3> decref
parents {<r,1>: {(<q,2>, 'at2')}, <p,1>: {(<q,2>, 'at')}, <q
,2>: {(<r,1>, 'at'), (<q,2>, 'at1')}, <t,2>: {(<q,2>, 'at3')
}}
refct_copy {<q,2>: 0, <r,1>: 0, <t,2>: 1, <p,1>: 0}
cycle of <q,2> found
<r,1> decref
<p,1> decref
<q,2> decref
<t,2> decref
finalizing <p,0>
<q,1> decref
finalizing <r,0>
finalizing <q,0>
parents {}
refct_copy {<t,1>: 1}
>>>
>>> assert_exist( t, u )
<t,1> exists
<u,1> exists
>>> assert_destroyed( p, q, r, s )
<p,0> destroyed
<q,0> destroyed
<r,0> destroyed
<s,0> destroyed
>>>
>>> run( 'psu' )

<q,4> decref
parents {<r,2>: {(<q,3>, 'at2')}, <p,3>: {(<q,3>, 'at')}, <q
,3>: {(<p,3>, 'at'), (<r,2>, 'at'), (<q,3>, 'at1')}, <t,3>:
{(<q,3>, 'at3')}}
refct_copy {<q,3>: 0, <r,2>: 1, <t,3>: 2, <p,3>: 2}
<r,2> decref
parents {<q,3>: {(<p,3>, 'at'), (<r,1>, 'at'), (<q,3>, 'at1'
)}, <r,1>: {(<q,3>, 'at2')}, <t,3>: {(<q,3>, 'at3')}, <p,3>:
 {(<q,3>, 'at')}}
refct_copy {<r,1>: 0, <q,3>: 0, <t,3>: 2, <p,3>: 2}
<t,3> decref
parents {}
refct_copy {<t,2>: 2}
p: (q), q: (pqrt), r: (q), s: (p), t: (), u: (t)
>>>
>>> s.decref() # should finalize 's'.
<s,1> decref
<p,3> decref
finalizing <s,0>
parents {<q,3>: {(<r,1>, 'at'), (<p,2>, 'at'), (<q,3>, 'at1'
)}, <r,1>: {(<q,3>, 'at2')}, <t,2>: {(<q,3>, 'at3')}, <p,2>:
 {(<q,3>, 'at')}}
refct_copy {<p,2>: 1, <q,3>: 0, <r,1>: 0, <t,2>: 1}
>>>
>>> assert_exist( p, q, r, t, u )
<p,2> exists
<q,3> exists
<r,1> exists
<t,2> exists
<u,1> exists
>>> assert_destroyed( s )
<s,0> destroyed
>>>
>>> run( 'qsu' ) # more.

<p,3> decref
parents {<q,4>: {(<r,2>, 'at'), (<p,2>, 'at'), (<q,4>, 'at1'
)}, <r,2>: {(<q,4>, 'at2')}, <p,2>: {(<q,4>, 'at')}, <t,3>:
{(<q,4>, 'at3')}}
refct_copy {<p,2>: 1, <q,4>: 1, <r,2>: 1, <t,3>: 2}
<r,2> decref
parents {<q,4>: {(<p,2>, 'at'), (<r,1>, 'at'), (<q,4>, 'at1'
)}, <r,1>: {(<q,4>, 'at2')}, <p,2>: {(<q,4>, 'at')}, <t,3>:
{(<q,4>, 'at3')}}
refct_copy {<r,1>: 0, <q,4>: 1, <p,2>: 1, <t,3>: 2}
<t,3> decref
parents {}
refct_copy {<t,2>: 2}
p: (q), q: (pqrt), r: (q), s: (p), t: (), u: (t)
>>>
>>> q.decref()
<q,4> decref
parents {<r,1>: {(<q,3>, 'at2')}, <p,2>: {(<q,3>, 'at')}, <q
,3>: {(<p,2>, 'at'), (<r,1>, 'at'), (<q,3>, 'at1')}, <t,2>:
{(<q,3>, 'at3')}}
refct_copy {<q,3>: 0, <r,1>: 0, <p,2>: 1, <t,2>: 1}
>>>
>>> assert_exist( p, q, r, s, t, u )
<p,2> exists
<q,3> exists
<r,1> exists
<s,1> exists
<t,2> exists
<u,1> exists
>>>
>>> run( 'qsu' )

<p,3> decref
parents {<q,4>: {(<r,2>, 'at'), (<p,2>, 'at'), (<q,4>, 'at1'
)}, <r,2>: {(<q,4>, 'at2')}, <p,2>: {(<q,4>, 'at')}, <t,3>:
{(<q,4>, 'at3')}}
refct_copy {<p,2>: 1, <q,4>: 1, <t,3>: 2, <r,2>: 1}
<r,2> decref
parents {<q,4>: {(<p,2>, 'at'), (<r,1>, 'at'), (<q,4>, 'at1'
)}, <r,1>: {(<q,4>, 'at2')}, <p,2>: {(<q,4>, 'at')}, <t,3>:
{(<q,4>, 'at3')}}
refct_copy {<r,1>: 0, <q,4>: 1, <p,2>: 1, <t,3>: 2}
<t,3> decref
parents {}
refct_copy {<t,2>: 2}
p: (q), q: (pqrt), r: (q), s: (p), t: (), u: (t)
>>>
>>> q.decref()
<q,4> decref
parents {<r,1>: {(<q,3>, 'at2')}, <p,2>: {(<q,3>, 'at')}, <t
,2>: {(<q,3>, 'at3')}, <q,3>: {(<p,2>, 'at'), (<r,1>, 'at'),
 (<q,3>, 'at1')}}
refct_copy {<q,3>: 0, <r,1>: 0, <p,2>: 1, <t,2>: 1}
>>>
>>> s.decref()
<s,1> decref
<p,2> decref
finalizing <s,0>
parents {<q,3>: {(<r,1>, 'at'), (<p,1>, 'at'), (<q,3>, 'at1'
)}, <r,1>: {(<q,3>, 'at2')}, <p,1>: {(<q,3>, 'at')}, <t,2>:
{(<q,3>, 'at3')}}
refct_copy {<p,1>: 0, <q,3>: 0, <t,2>: 1, <r,1>: 0}
cycle of <p,1> found
<q,3> decref
parents {<r,1>: {(<q,2>, 'at2')}, <p,1>: {(<q,2>, 'at')}, <t
,2>: {(<q,2>, 'at3')}, <q,2>: {(<r,1>, 'at'), (<q,2>, 'at1')
}}
refct_copy {<q,2>: 0, <r,1>: 0, <p,1>: 0, <t,2>: 1}
cycle of <q,2> found
<r,1> decref
<p,1> decref
<q,2> decref
<t,2> decref
finalizing <p,0>
<q,1> decref
finalizing <r,0>
finalizing <q,0>
parents {}
refct_copy {<t,1>: 1}
>>>
>>> assert_exist( t, u )
<t,1> exists
<u,1> exists
>>> assert_destroyed( p, q, r, s )
<p,0> destroyed
<q,0> destroyed
<r,0> destroyed
<s,0> destroyed
>>>
>>> run( 'qsu' )

<p,3> decref
parents {<q,4>: {(<r,2>, 'at'), (<p,2>, 'at'), (<q,4>, 'at1'
)}, <r,2>: {(<q,4>, 'at2')}, <p,2>: {(<q,4>, 'at')}, <t,3>:
{(<q,4>, 'at3')}}
refct_copy {<p,2>: 1, <q,4>: 1, <t,3>: 2, <r,2>: 1}
<r,2> decref
parents {<q,4>: {(<p,2>, 'at'), (<r,1>, 'at'), (<q,4>, 'at1'
)}, <r,1>: {(<q,4>, 'at2')}, <p,2>: {(<q,4>, 'at')}, <t,3>:
{(<q,4>, 'at3')}}
refct_copy {<r,1>: 0, <q,4>: 1, <p,2>: 1, <t,3>: 2}
<t,3> decref
parents {}
refct_copy {<t,2>: 2}
p: (q), q: (pqrt), r: (q), s: (p), t: (), u: (t)
>>>
>>> s.decref()
<s,1> decref
<p,2> decref
finalizing <s,0>
parents {<q,4>: {(<r,1>, 'at'), (<p,1>, 'at'), (<q,4>, 'at1'
)}, <r,1>: {(<q,4>, 'at2')}, <p,1>: {(<q,4>, 'at')}, <t,2>:
{(<q,4>, 'at3')}}
refct_copy {<p,1>: 0, <q,4>: 1, <t,2>: 1, <r,1>: 0}
>>>
>>> q.decref()
<q,4> decref
parents {<r,1>: {(<q,3>, 'at2')}, <p,1>: {(<q,3>, 'at')}, <q
,3>: {(<p,1>, 'at'), (<r,1>, 'at'), (<q,3>, 'at1')}, <t,2>:
{(<q,3>, 'at3')}}
refct_copy {<q,3>: 0, <r,1>: 0, <p,1>: 0, <t,2>: 1}
cycle of <q,3> found
<r,1> decref
<p,1> decref
<q,3> decref
<t,2> decref
<q,2> decref
finalizing <r,0>
<q,1> decref
finalizing <p,0>
finalizing <q,0>
parents {}
refct_copy {<t,1>: 1}
>>>
>>> assert_exist( t, u )
<t,1> exists
<u,1> exists
>>> assert_destroyed( p, q, r, s )
<p,0> destroyed
<q,0> destroyed
<r,0> destroyed
<s,0> destroyed
>>>
>>> run( 'qsu' )

<p,3> decref
parents {<q,4>: {(<r,2>, 'at'), (<p,2>, 'at'), (<q,4>, 'at1'
)}, <r,2>: {(<q,4>, 'at2')}, <p,2>: {(<q,4>, 'at')}, <t,3>:
{(<q,4>, 'at3')}}
refct_copy {<p,2>: 1, <q,4>: 1, <r,2>: 1, <t,3>: 2}
<r,2> decref
parents {<q,4>: {(<p,2>, 'at'), (<r,1>, 'at'), (<q,4>, 'at1'
)}, <r,1>: {(<q,4>, 'at2')}, <p,2>: {(<q,4>, 'at')}, <t,3>:
{(<q,4>, 'at3')}}
refct_copy {<r,1>: 0, <q,4>: 1, <p,2>: 1, <t,3>: 2}
<t,3> decref
parents {}
refct_copy {<t,2>: 2}
p: (q), q: (pqrt), r: (q), s: (p), t: (), u: (t)
>>>
>>> s.decref()
<s,1> decref
<p,2> decref
finalizing <s,0>
parents {<q,4>: {(<r,1>, 'at'), (<p,1>, 'at'), (<q,4>, 'at1'
)}, <r,1>: {(<q,4>, 'at2')}, <p,1>: {(<q,4>, 'at')}, <t,2>:
{(<q,4>, 'at3')}}
refct_copy {<p,1>: 0, <q,4>: 1, <r,1>: 0, <t,2>: 1}
>>>
>>> assert_exist( p, q, r, t, u )
<p,1> exists
<q,4> exists
<r,1> exists
<t,2> exists
<u,1> exists
>>> assert_destroyed( s )
<s,0> destroyed



More information about the Python-list mailing list