←back to thread

131 points b-man | 1 comments | | HN request time: 0.207s | source
Show context
BlimpSpike ◴[] No.44539960[source]
Kindof unrelated to the article, but I was recently wondering if it would be possible to detect and deny pointer cycles in a language in an efficient way, so that you could then use simple reference counting instead of full-blown garbage collection.

It probably wouldn't be usable for a general-purpose programming language, but for a special-purpose scripting language I could see it making the language implementation easier.

replies(7): >>44539978 #>>44540061 #>>44540517 #>>44540551 #>>44541083 #>>44541588 #>>44541966 #
louthy ◴[] No.44539978[source]
On any one object you can just follow the references to see if you get back to the same object. Not super efficient as you’d have to do it for each reference as it is set.

But if it was a simple scripting language and you needed that constraint, it’s relativity easy to implement.

replies(1): >>44542059 #
1. Findecanor ◴[] No.44542059[source]
That would still be tracing. The problem is that if there is a cycle, the reference count would be too high, and you'd not detect that the object should be reclaimed.