The future of Ruby bindings

Subject: The future of Ruby bindings

Date: Fri, 30 Apr 2021 17:14:15 -0500


Cc: Ali Polatel

From: Felipe Contreras


Ruby is by far my favorite programming language, and I'm very familiar
with the way it's meant to be used.

This is very idiomatic of Ruby:

  $db.query('').search_threads.each do |thread|
    puts thread.subject

It works perfectly fine, but it leaks memory.

In order to prevent memory from being leaked, we have to do something

  query = $db.query('')
  threads = query.search_threads
  threads.each do |thread|
    puts thread.subject

This is very ugly Ruby.

Ruby is a garbage collected language, this destroy! approach works, but
there's no better way to describe it but "a hack".

I understand why Ali Polatel did commit c7893408 (ruby: Kill garbage
collection related cruft., 2010-05-26); because the order of the object
destruction cannot be ensured in Ruby, however, there's ways to
workaround that.

 1. We can steal the object
 2. We can increase the reference count
 3. We can add a second parent

The notmuch API doesn't have helpers to do either one of those things,
but since we know talloc is used internally, we can simply utilize that

I sent a proof of concept patch [1], that uses method 3, but it was

I could proceed and do the actual full patch using this method over all
the Ruby code, but it's tedious work that I would rather not do until I
know such an approach would be accepted.

With my proposed approach we wouldn't have to rely on destroy! (which
still works), and Ruby's garbage collection would work fine and no
memory would be leaked.




Felipe Contreras
notmuch mailing list --
To unsubscribe send an email to