From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46924) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yuk6s-0004QQ-VH for qemu-devel@nongnu.org; Tue, 19 May 2015 12:11:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yuk6o-0003MD-35 for qemu-devel@nongnu.org; Tue, 19 May 2015 12:11:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48790) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yuk6n-0003Le-Q4 for qemu-devel@nongnu.org; Tue, 19 May 2015 12:11:10 -0400 Message-ID: <555B6099.4060803@redhat.com> Date: Tue, 19 May 2015 18:11:05 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1431533649-23115-1-git-send-email-berrange@redhat.com> <1431533649-23115-6-git-send-email-berrange@redhat.com> <555B5C2E.5050903@suse.de> <20150519155528.GF8535@redhat.com> In-Reply-To: <20150519155528.GF8535@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v4 5/8] qom: add object_new_with_props / object_new_withpropv constructors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , =?UTF-8?B?QW5kcmVhcyBGw6Ry?= =?UTF-8?B?YmVy?= Cc: qemu-devel@nongnu.org On 19/05/2015 17:55, Daniel P. Berrange wrote: > Paolo told me on previous posting that object_property_add_child() > holds a reference on 'obj' for as long as it is registered in the > object hierarchy composition. So it sufficient to rely on that long > term reference, and let the caller dispose of the object by calling > object_unparent(obj) when finally done. For an example of the same pattern: DeviceState *qdev_try_create(BusState *bus, const char *type) { DeviceState *dev; if (object_class_by_name(type) == NULL) { return NULL; } dev = DEVICE(object_new(type)); if (!dev) { return NULL; } if (!bus) { bus = sysbus_get_default(); } qdev_set_parent_bus(dev, bus); object_unref(OBJECT(dev)); return dev; } Effectively this is idea as GObject's "floating reference". qdev_set_parent_bus (in qdev_try_create) and object_property_add_child (in Daniel's patches) "sink" the floating reference by doing object_unref. If we had floating references, the object would be returned to the caller unref'ed anyway. Of course, the reference can go away via QMP. But that will only happen after the caller would have called object_unref itself. Paolo