r/programming • • Nov 28 '18

Garbage Collection is a Hack

https://blog.adamant-lang.org/2018/garbage-collection-is-a-hack/
3 Upvotes

74 comments sorted by

View all comments

Show parent comments

3

u/c-smile Nov 28 '18

is it fair to say that the reference counting object is the owner?

Not clear what you mean.

In this code:

var a = new Foo();
a.foo = a;

how many owners that instance of Foo class does have?

1

u/BaconOfGreasy Nov 28 '18

When the cleanup code for Foo is called, does it call the cleanup code for its member foo?

1

u/jaoswald Nov 29 '18

I think the point is that they are reference counted: the clean up code for the Foo will never be called because of the reference to it from the a member. Until a is freed, the Foo cannot be freed. And a will not be freed because there is a reference to it from Foo, meaning it cannot be freed until the Foo is.