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|
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|
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
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 , 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.