On Mon, Jan 26, 2009 at 05:04:39PM +0100, Tom Cooksey wrote:
> So, GetPalette() allocates a new Palette Interface object, which references 
> the source surface's real palette. Creating the interface object also 
> increments the real palette's ref count. When I call SetPalette(), the dest 
> surface also increments the real palette's ref count. So in all of this, 
> there's only one real palette. The real palette's ref count is three: One for 
> the src surface, one for the interface object and one for the dest surface.

Yes.

> To make sure the real palette is freed when the last surface is released, I 
> must call Release on the palette interface object.

Yes.

> This will actually 
> decrement the ref count on the real palette (making it 2, one for src & dest 
> surfaces).

That is usually the result but the real  story is a bit more complicated.
The interface object itself is reference counted. The reference count is
1 when you create the object. Calling Release() on it will decrement that
reference count (AddRef() can be used to increase the ref count). When
the ref count reaches 0 the interface object's destructor is called which
will drop the reference on the real palette (CorePalette).

But normally you don't really have to think about this stuff. Just
follow the simple rule of calling Release() on all interface objects
you created when you no longer need them.

> > > If I understand what you're saying it does, but SetPalette will then take
> > > ownership of it, calling delete when it's destroyed. But I still have to
> > > call Release on the newly created object to decrement it's ref count.
> > > Otherwise, when the new surface is destroyed it won't delete the palette
> > > because it's ref count > 1?
> >
> > SetPalette will not touch the interface reference count.
> > So no taking ownership there.
> 
> But this sounds to me that I'm also going to end up with the interface object 
> never being deleted. Surely if the dest surface doesn't take ownership of the 
> interface object in SetPalette, I'm responsible for freeing it? So I need to 
> call release and then delete?

There is no delete. Just Release().

-- 
Ville Syrjälä
syrj...@sci.fi
http://www.sci.fi/~syrjala/
_______________________________________________
directfb-users mailing list
directfb-users@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users

Reply via email to