From: Felipe Contreras <felipe.contreras@gmail.com>
To: notmuch@notmuchmail.org
Cc: Ali Polatel <alip@exherbo.org>
Subject: The future of Ruby bindings
Date: Fri, 30 Apr 2021 17:14:15 -0500 [thread overview]
Message-ID: <608c81378d0d0_fea2086d@natae.notmuch> (raw)
Hi,
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
end
It works perfectly fine, but it leaks memory.
In order to prevent memory from being leaked, we have to do something
like:
query = $db.query('')
threads = query.search_threads
threads.each do |thread|
puts thread.subject
thread.destroy!
end
threads.destroy!
query.destroy!
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
knowledge.
I sent a proof of concept patch [1], that uses method 3, but it was
ignored.
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.
Thoughts?
Cheers.
[1] id:20210427085343.2300-1-felipe.contreras@gmail.com
--
Felipe Contreras
next reply other threads:[~2021-04-30 22:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-30 22:14 Felipe Contreras [this message]
2021-05-08 6:28 ` The future of Ruby bindings Felipe Contreras
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=608c81378d0d0_fea2086d@natae.notmuch \
--to=felipe.contreras@gmail.com \
--cc=alip@exherbo.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).