On Monday 26 January 2009 15:58:50 ext Niels Roest wrote: > Tom Cooksey wrote: > > On Monday 26 January 2009 13:04:59 ext Denis Oliver Kropp wrote: > >> Denis Oliver Kropp wrote: > >>> Tom Cooksey wrote: > >>>> What is GetPalette actually supposed to do? I assume from the docs it > >>>> will just return a pointer to the surface's palette? However I'm being > >>>> told that it's showing up in profiling as a memory leak. Does > >>>> GetPalette allocate any memory? I.e. Do I need to either delete and/or > >>>> Relese it after setting the dest's palette? > >>> > >>> Yes, SetPalette() AddRef's IDirectFBPalette, so Release() it! > >> > >> Not exactly: GetPalette() creates a new instance of IDirectFBPalette > >> while SetPalette() only uses the underlying CorePalette (FusionObject), > >> increasing its reference count, but not that of IDirectFBPalette > >> (Interface). > >> > >> But still you should Release() the interface that has been created by > >> GetPalette(). > > > > I don't really understand the semantics here... Does > > IDirectFBSurface::GetPalette() actually allocate a new object on the > > heap? > > Yes, GetPalette allocates an 'interface'. > However, the referenced Palette only gets an AddRef. > So you need to do Release on ipalette to deallocate the 'interface'. > This will also lower the palette reference (which might lead, as a > consequence, to clean-up of the palette).
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. To make sure the real palette is freed when the last surface is released, I must call Release on the palette interface object. This will actually decrement the ref count on the real palette (making it 2, one for src & dest surfaces). > > 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? Cheers, Tom _______________________________________________ directfb-users mailing list directfb-users@directfb.org http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users