From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:37354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rs8Sy-0004Os-Km for qemu-devel@nongnu.org; Tue, 31 Jan 2012 02:49:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rs8St-0005W3-1C for qemu-devel@nongnu.org; Tue, 31 Jan 2012 02:49:24 -0500 Received: from mail-yx0-f173.google.com ([209.85.213.173]:41363) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rs8Ss-0005Vz-Tf for qemu-devel@nongnu.org; Tue, 31 Jan 2012 02:49:18 -0500 Received: by yenl10 with SMTP id l10so105843yen.4 for ; Mon, 30 Jan 2012 23:49:18 -0800 (PST) Sender: Paolo Bonzini Message-ID: <4F279CFA.9040105@redhat.com> Date: Tue, 31 Jan 2012 08:49:14 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1327957741-5842-1-git-send-email-aliguori@us.ibm.com> <1327957741-5842-21-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1327957741-5842-21-git-send-email-aliguori@us.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 21/23] object: sure up reference counting List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Peter Maydell , Andreas Faerber , qemu-devel@nongnu.org On 01/30/2012 10:08 PM, Anthony Liguori wrote: > Now we have the following behavior: > > 1) object_new() returns an object with ref = 1 > 2) object_initialize() does not increase the reference count (ref may be 0). > 3) object_deref() will finalize the object when ref = 0. it does not free the > memory associated with the object. > 4) both link and child properties correctly set the reference count. > > The expected usage is the following: > > 1) child devices should generally be created via object_initialize() using > memory from the parent device. Adding the object as a child property will > take ownership of the object and tie the child's life cycle to the parent. > > 2) If a child device is created via qdev_create() or some other form of > object_new(), there must be an object_delete() call in the parent device's > finalize function. We might want to fix this by adding a special "created as child" refcount value, so that the object_delete can still be automatic. Adding floating references as they have them in GObject is also possible. I agree that it can be left for later, though. Paolo