views:

65

answers:

2

Possible Duplicate:
Why are circular dependencies considered harmful?

I have a line object and a point object. A line has references to two points, and each point has a reference back to the line object it belongs to.

I have heard somewhere (I think) that circular references are a bad thing, but I don't understand why. Can someone fill me in with some details?

A: 

One way they could be a problem is with Garbage Collectors. Because they hold a reference to eachother, they ought to not find the objects eligible for collection. But most garbage collectors have detection for circular depencies and collect them anyway.

See also this question.

Ikke
+1  A: 

Reference counting is a common technique for memory/resource management, and circular references don't play well with it. If object A contains a reference to object B, and object B contains a reference to object A, then both objects have a reference count of 1 and can't be garbage collected, even if neither are referenced from anywhere else.

More sophisticated garbage collectors are capable of dealing with cycles so this problem doesn't occur.

dan04