[PATCH] ruby: make sure the database is closed

Ali Polatel alip at exherbo.org
Mon Apr 23 13:43:04 PDT 2012


2012/4/23 Felipe Contreras <felipe.contreras at gmail.com>:
> On Mon, Apr 23, 2012 at 5:04 PM, Ali Polatel <alip at exherbo.org> wrote:
>
>> I'd rather not do this.
>> Please read: http://comments.gmane.org/gmane.comp.lang.ruby.general/320324
>
> OK, I've read this.. So?

You are one step close to what I thought you had thought.

> The order in which Ruby's garbage-collector frees the database and
> other objects is irrelevant, because with this patch we are not
> manually freeing other objects, only the database.

What I wanted was to make all objects "depending" on the database to be unusable
once the database object is freed. Seeing that's not practically easy
I decided to leave
it to the user.

> Sure, it's _better_ if the user calls close(), even better if it's
> inside an 'ensure', and even better if blocks are used (which I am
> using in most cases), but that's not *required*.

If you have such a use case, I'm fine with that patch.
I might push it in the next few days or get someone else to push it.

> The user might just do:
>
> def foo
>  db = Notmuch::Database.new($db_name, :mode => Notmuch::MODE_READ_WRITE)
> end
>
> That's perfectly fine in Ruby (although not ideal), since 'db' will
> get garbage-collected. But nobody will be able to use the database
> again until that process is killed.
>
> You think that's correct?

Yes that is correct. I have not thought about this.
I'd say it's a partial misunderstanding on my part due to lack of
(and/or too much) vodka.

> --
> Felipe Contreras

        -alip


More information about the notmuch mailing list