in reply to Re: Intercept any changes to the sv_refcnt/SvREFCNT of an object
in thread Intercept any changes to the sv_refcnt/SvREFCNT of an object

It's hard to tell if this could be applied to your application, but the easiest way to deal with the circular references problem is to avoid it.

Instead of storing references to other objects within your objects, store your objects in an array, and then store indexes to the parent/child within the object.

package Family; my @objs; sub new { my( $parent, $child, %otherstuff ) = @_; push @objs, my $self = bless \%otherstuff, __PACKAGE__; $self->id( $#objs ); $self->parent( $parent->id ); $self->child( $child->id ); return $self; }

It's one extra level of indirection, but no circular references.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^2: Intercept any changes to the sv_refcnt/SvREFCNT of an object
  • Download Code