Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 5A5CD431FD0 for ; Mon, 19 Sep 2011 13:22:47 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=unavailable Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id atN+JPvXWxCr for ; Mon, 19 Sep 2011 13:22:47 -0700 (PDT) Received: from mail-qy0-f174.google.com (mail-qy0-f174.google.com [209.85.216.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 254A6431FB6 for ; Mon, 19 Sep 2011 13:22:47 -0700 (PDT) Received: by qyk30 with SMTP id 30so2997508qyk.5 for ; Mon, 19 Sep 2011 13:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:user-agent:date:message-id:mime-version :content-type; bh=AcO7ahhQfeyc8tCUzjQu+yt5F07WKS0LXCvtPzb07k0=; b=jBVPcfG4Futp+pTENmfplYxIq0Ivt1LNVdqgUq6vxQQiH+XGJguFRKUgzsw7qUlT6E pVp6oK06FM6FqqUZxRmD/dFOJrw6mZAeTgpIyHzFAxqfkRejgImHoLPUIZrgdh7UarqF sRqppRZDBWsgIwOqenWyu0PSt9tOFGIHgBcgc= Received: by 10.229.227.67 with SMTP id iz3mr2392203qcb.296.1316463764975; Mon, 19 Sep 2011 13:22:44 -0700 (PDT) Received: from localhost (pool-96-233-180-23.spfdma.east.verizon.net. [96.233.180.23]) by mx.google.com with ESMTPS id du8sm4565405qab.11.2011.09.19.13.22.40 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Sep 2011 13:22:41 -0700 (PDT) From: Ben Gamari To: notmuch Subject: Rethinking *_destroy() User-Agent: Notmuch/0.7-37-g5c3c7f6 (http://notmuchmail.org) Emacs/23.2.1 (x86_64-pc-linux-gnu) Date: Mon, 19 Sep 2011 16:22:39 -0400 Message-ID: <87aaa0l1tc.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Bertram Felgenhauer , Bart Massey , Austin Clements , notmuch X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Sep 2011 20:22:47 -0000 As many might have noticed, there was recently a bit of a discussion on this list concerning the state of memory management in libnotmuch, especially regarding some classes of garbage collectors. To summarize (someone correct me if I get something wrong), * Garbage collectors don't always dispose of objects in the order that they become unreachable (due to the fact that in the existence of cycles, this order is not well-defined). * Notmuch emulates a C-style free() function (which we call *_destroy()) on top of talloc * Calling *_destroy() on an object (e.g. Query) will also cause its children (e.g. Messages) to be freed * Calling *_destroy() on an object which has already been freed (not surprisingly) causes talloc to abort Overall, this means that languages with cyclical garbage collectors (Python, Haskell, and I'm sure others) can not bind libnotmuch correctly. In the case of my work on the Haskell binding, I've found that very often Query objects are released before Messages, quickly causing talloc to abort. The solution as suggested my several people is for notmuch to expose its reference counting mechanism (which even the problems with *_destroy() notwithstanding, seems like a more natural means of memory management, IMHO). I can see at least two ways of doing this, 1) Acknowledging that we use talloc and allowing users to use talloc_ref and talloc_unlink directly 2) Wrapping talloc by adding a *_ref() and *_unref() to each object Additionally, we need to decide to what extent we want to break the libnotmuch API. While strictly speaking we could keep *_destroy() around without breaking existing code, this will mean we will have two ways of freeing an object. Perhaps a scheduled deprecation in a release or two is in order here? Anyways, I strongly believe that one of the above actions should be taken as the current state of affairs is unacceptable for binding writers. Any and all feedback is desired. Cheers, - Ben