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?

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?

So if I did IDirectFBSurface::GetPalette() and _didn't_ pass the returned 
object to SetPalette, I'd also have to delete it? Otherwise I'd get a memory 
leak?


Cheers,

Tom

_______________________________________________
directfb-users mailing list
directfb-users@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users

Reply via email to