From: ts Date: 2004-07-31T19:32:40+09:00 Subject: Re: C ext: GC claiming objects early >>>>> "T" == Tilman Sauerbeck writes: T> Yeah. Although if I make the parent object (the XmmsClient, 'o') know T> about (and mark) the Result objects, I've got a circular reference, T> since the result objects mark their parent, which is 'o'. Circular reference is not a problem because the GC is a mark-sweep GC. bdb use circular reference and it work fine. For example (this is cats.rb) def tt bdb = BDB::Btree.open "tmp/aa", nil, "w", "marshal" => true aux = BDB::Btree.open "tmp/bb", nil, "w", "set_flags" => BDB::DUPSORT, "marshal" => true bdb.associate(aux) { |aux1, key, value| value.life } nil end tt GC.start `bdb' will mark `aux' and `aux' will mark `bdb' When the GC run, it will not mark `bdb' because it has no reference to it, and it will not mark `aux' for the same reason. At the sweep phase, `bdb' and `aux' are removed (closed in this case) Now with def tt bdb = BDB::Btree.open "tmp/aa", nil, "w", "marshal" => true aux = BDB::Btree.open "tmp/bb", nil, "w", "set_flags" => BDB::DUPSORT, "marshal" => true bdb.associate(aux) { |aux1, key, value| value.life } bdb end a = tt GC.start the GC will mark `a' (i.e. `bdb') which mark `aux' (same if it return `aux' rather than `bdb') Guy Decoux