Client memory leak with XCopyArea() call?

Ryan B. Lynch rlynch at bway.net
Fri Apr 8 10:17:58 PDT 2005


I'm pretty new to Xlib programming, and I'm observing a behavior that 
seems like a memory leak.  I'm using x11 6.7.0, right now, compiled from 
source on CRUX Linux.

First, I create a window.

Then, in a while(1) loop, I:
    - call XCreatePixmap() to instantiate a new pixmap,
    - draw some stuff on the pixmap,
    - call XCopyArea to copy the pixmap contents to the window,
    - call XFreePixmap to destroy the pixmap.

When the program runs, I notice that the memory usage of my program 
starts climbing and climbing--eventually, it exhausts memory.  Seems 
like a memory leak, right?

I don't understand what's going on, though, because the XFreePixmap() 
call should free the memory that's being allocated by each new pixmap, 
right?  Does XFreePixmap guarantee that the memory used by that pixmap 
is completely freed, or what?

I noticed something strange, also:  if I remove the call to XCopyArea(), 
the memory leak doesn't happen.  If I just run the loop (uselessly) to 
do this:
    - call XCreatePixmap() to instantiate a new pixmap,
    - draw some stuff on the pixmap,
    - call XFreePixmap to destroy the pixmap,
then the memory usage stays pretty constant.  No memory leak.

Any idea why calling XCopyArea causes this behavior?  I can post some 
sample code to illustrate the problem, if need be.

Thanks,
Ryan B. Lynch



More information about the xorg mailing list