nanogui: XCreateWindow/XDestroyWindow memory leak?
Subject:
Re: [nanogui] XCreateWindow/XDestroyWindow memory leak?
From:
Hermann Ulrichskoetter ####@####.####
Date:
13 Nov 2007 22:32:28 +0000
Message-Id: <473A25F7.30306@gmx.de>
on 13.11.07 21.34 Greg Haerr wrote:
>> This reduced the amount of memory not deallocated by windows but there
> is still something not being deallocated.
>
> Put a printf() in the other XSetClip function to see whether
> this might be the other leak, or whether we should still look
> hard at ChProperties.c
>
Some long time ago I had that problem with XSetClip() and FLTK too and made a modification that
solved the problem for me.
Hermann
int XSetClipMask(Display *display, GC gc, Pixmap mask)
{
static GR_GC_ID last_gc_gid = 0;
static GR_REGION_ID last_region = 0;
GR_REGION_ID r;
GR_WINDOW_INFO info;
// to avoid a memory leak, delete region if last region hasn't been deleted before
if ( (last_gc_gid == gc->gid) && (last_region != 0) )
{
GrDestroyRegion(last_region);
//printf("XSetClipMask remove %d %d %d\n", mask, last_gc_gid, last_region);
last_region = 0;
last_gc_gid = 0;
}
else
{
//printf("XSetClipMask NO remove %d %d %d\n", mask, last_gc_gid, last_region);
}
if (mask == None) {
GrSetGCRegion(gc->gid, 0);
return 1;
}
GrGetWindowInfo(mask, &info);
r = GrNewRegionFromPixmap(mask, 0, 0, info.width, info.height);
GrSetGCRegion(gc->gid, r);
last_region = r;
last_gc_gid = gc->gid;
//printf("XSetClipMask crate %d %d %d\n", mask, last_gc_gid, last_region);
/*GrDestroyRegion(r);*/ /* FIXME: LEAK: can't destroy region here...*/
return 1;
}