Re: Garbage Collection
- Posted by Robert Craig <rds at RapidEuphoria.com> Jun 28, 2005
- 658 views
Vincent wrote: > I just concluded after reading a bunch of stuff online, that Robert should > just stick with > either pure reference counting or use a hybrid reference counting & trace > garbage collector > to handle cyclic structures. > > The problem with reference counting besides implementing mutex locks properly > is, objects > within cyclic structures will never obtain a zero reference count, and the > unused block > will never be freed). > > But Rob claims Euphoria ignores cyclic structures of pointers. Are the garbage > blocks > still freed by a conversion, or just left to build up? In parser.e where assignments to subscripted variables are handled, there's a tiny bit of code that prevents cycles. So the cycle problem they always talk about doesn't exist. Cycles do not happen. Here's how a cycle could occur (without precautions): A[5] = A You might just store a pointer to A in A[5]. That means A[5] will point to A, but A will also contain a pointer to A[5], since A[5] is an element of the sequence A. That's circular. The ref count on A will never drop to zero, because A[5] points at it. The ref count on A[5] will never drop to zero, because A points at it. Euphoria avoids this problem by making a copy of A (call it A_TEMP) and pointing A[5] at the *copy*, rather than at the original sequence that A[5] is a part of. So there's no cycle. A points to A[5] which points to A_TEMP, and A_TEMP[5] points wherever A[5] originally pointed (if anywhere). This costs some time because a copy of A is made, but this is a rare case. Not many people do A[5] = A. It's strange code. But the bottom line is Euphoria can use reference counting without worrying about cycles. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com