As I am developing my code in Ruby/C, I cannot help to ask the question,
why does Ruby use the mark-and-sweep gc, instead of reference counting
such as that used by Python?
For the majority of Ruby codes, probably the kind of gc does not matter
(just as when I first coded in Ruby), but now when I started to code in C,
it seems that the mark-and-sweep gc can really get in the way.
I think one of the problems with reference counting is the circular
reference, which cannot be handled by the gc. However, now the problems
with mark-and-sweep gc for my specific applications are:
It is linear (O(N)) in the number of Ruby objects, and therefore it
seems that it will not scale well. Yes, probably for the majority of Ruby
applications, the cost of gc invocation is small as compared to all the
other functions in the Ruby code, i.e.,
cost = eps * N
where eps is a small number. However, no matter how small eps is, as N
grows large, eventually the gc cost cannot be neglected.
- When the Ruby objects are static, gc invocation is a waste.
Regarding 2), I think I can solve it by manually disabling and invoking
gc. However, I still cannot solve 1). Therefore,
"Is there a way to manually and explicitly delete a Ruby object (from
C), just like Python’s delete function, so that the sweep (and mark) phase
needs not be done?"
I never had a formal training on the subject of gc, and therefore I don’t
know whether my question above is simply impossible because of the
fundamental natures of mark-and-sweep gc.