qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 21/23] object: sure up reference counting


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH 21/23] object: sure up reference counting
Date: Tue, 31 Jan 2012 08:49:14 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111222 Thunderbird/9.0

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]