work around for circular reference retain count limitation?
work around for circular reference retain count limitation?
- Subject: work around for circular reference retain count limitation?
- From: Wesley Tam <email@hidden>
- Date: Wed, 9 Apr 2003 16:53:12 -0400
Hello,
Recently we have been developed an architecture of objects where, in
the simplest case, a bidirectional aggregate relation can exist between
two objects. Note that the life-times of the two objects are totally
independent of each other.
I am currently looking for a good workaround to the circular reference
retain count limitation. I've illustrated a simple case of the problem
for clarity, additionally the relationship between the the two objects
is an aggregation as opposed to a composite:
Suppose two instances with life-times that are totally independent of
each other. At some point in time Object A references Object B, and
Object B references object A. This creates a circular references
between the two objects. The reference count of each instance is
incremented and because of this, they can never be released (i guess
this is kind of like deadlock where each object is waiting for the
other release before itself will).
Now this illustrates the limitation of the retain-count memory
management system. In the past, i've just carefully, and selectively
delegated the retains that are called when these binding is created,
but i find this a bit of a clumsy solution and it doesn't scale up to
when you have an object that has many bidirectional links; it makes
code difficult to maintain as well. I've also looked at creating a
'destroy' method that would remove any bidirectional links with the
object that is being deleted, before calling release, (but there are
some obvious problems with this solution; in essence this is a explicit
destructor call so some object would have to be given responsibility
for this task). I've also looked at storing handles to objects as
opposed to storing the actual pointer, With this solution the object
would have to look up the adjacent object from some Singleton that
consisted of a list of possible objects, but this solution seems kind
of clumsy as well and can be a bit slow with large sets of objects.
I've briefly looked at Ken Case Weak Link solution at:
http://www.cocoadev.com/index.pl?WeakReferences (what do you think of
his approach?) and one at
http://h-world.simugraph.com/docs/refcount.html (I'm not fond of this
solution).
I'm curious as to the best way to address this problem, drawbacks, and
if there is a clean and scalable solution that can be relatively easy
to integrate. Any help or suggestions would be greatly appreciated;
Thanks for your help and insight.
Wesley T. | Software Developer | NOITAMINANIMATION |
www.noitaminanimation.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.