Question

I read some article about ruby garbage collector and many mentioned about circular reference object can not be cleared. This article mentioned about circular reference but I'm not sure whether it will cause the problem. Any one could give some examples of how to create a circular references?

Was it helpful?

Solution

I read some article about ruby garbage collector and many mentioned about circular reference object can not be cleared.

That's absolutely not true.

Any one could give some examples of how to create a circular references?

Most trivially like this:

arr1 = []
arr2 = [ arr1 ]
arr1 << arr2

However, as I said (and as the answer to the question you linked also points out), Ruby's GC will have absolutely no problem collecting arr1 and arr2 after they go out of scope.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top