Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memory leak in Xlib function Xcopyarea 1

Status
Not open for further replies.

Themuppeteer

Programmer
Apr 4, 2001
449
0
0
BE
Hello I'm working with RED LINUX 6.0 and
I'm programming C++ (duh). I have noticed that there's
a memory leak in Xcopyarea(...) (an Xlib function that is used very often)
I draw gifs on my screen, and for each gif I draw, I lose about 0.1K,when I put then Xcopyarea-line in // comment,
there is no leak (but also no drawing of course)
Does anyone have the same problem ? Does anyone know something about it ?


please let me know.
The Muppeteer.



Don't eat yellow snow...
 
I work with X-Windows a great deal and have never encountered the memory-leak problem you mention.
Most expose events depend upon XCopyArea to repaint the exposed area and I suspect that if it was troublesome then memory leaks would go into the stratosphere !

I run on SGI workstations and PCs with Linux/SuSE 7.1. Can you supply a little code that calls the XCopyArea function ?
 
Thnx for the reply,

Here's some code...

int myclass::draw()
{

XcopyArea(display,pixmap,window,gc,0,0,width,height,winx,winy);
}

Like I said, without the Xcopyarea,no memory is wasted.
If the process stops the leaked memory is released again...
I've cheked it with the "top"-commando.

The Muppeteer.



Don't eat yellow snow...
 
Your code looks fine, though I notice that the window is
not the same size as the pixmap - nothing wrong with that of course, so long as no part of the copied pixmap will extend outside of the bounds of the window.

Other than that, all I can think of is the implementation of X-Windows under Red Hat is faulty ... heresy, I know.

As a matter of interest, do you use XCopyArea to handle the repainting of windows when expose events occur ?

copying the contents of the pixmap
 
That last line in the above message was an error.

Something else occurs to me. Silly, I know, but you
do release the pixmap memory when you're through ?
Yes, of course you do. Just thought I'd mention it 'cos
it's the sort of thing I do ...
 
Yes,I'll reuse xcopyarea for the repaint, why shouldn't I ?

Yes,I release the memory, the class was made to load a gif once, and then redraw the same gif over and over again,so all it has to do is redraw the same gif, no need to release that memory while I still use it :)
But when the program finishes memory is released...
The Muppeteer.



Don't eat yellow snow...
 
Yes, you should use XCopyArea for the repaint, I wasn't implying you shouldn't. I just thought that if XCopyArea
was to blame for the memory leak, then other XCopyArea
calls in your program would exhibit a memory leak too.

And it is also true that if you are using the same pixmap
to hold the gif file, there is no need to release the pixmap
until the end of the program when normal garbage collection comes into play anyhow.

Presumably you construct the pixmap from an XImage structure
(to hold the RGB values of the original gif file). I not suggesting that there is anything wrong with the pixmap construction, just putting forward an idea for the memory problem.

Anyhow, good luck with the solution.
 
Well, i don't think it can be anything else then the xcopyarea, because when I but it in comment with // there is no leak at all. Without the // its leaking...
I only have one paint function,so one leak :)

Do you know what is funny to0? An animated Gif is leaking continuously because it does xcopyarea over and over again.
Most people wont notice this because nobody (almost nobody) lets an animated gif on his screen for a long time (and even if they did,the leak is quit small), but if you put up a while bunch of animated gifs on a screen and you let it run for a few days,...just check your memory,its shrinking and shrinking... The Muppeteer.



Don't eat yellow snow...
 
Ok,now that my book (Xlib programming manual) finally arrived ,my knowledge about this stuff has increased a little (thank god :)). Now I know a descent explenation about this memory leak wich isn't a memory leak at all!

The problem with XCopyArea was that it produces an event, an exposure event. If you don't handle those events,they heap up in memory and thats where the 'leak' is.
How to solve this ?
Just ask your gc nicely to stop doing stuff like that!

XSetGraphicsExposures(display,gc,false);

this line solved all my problems :)
its better than the previous solution cause just throwing the next event away with XNextEvent just can't be right,not producing them can.

Thnx for the replies!


The Muppeteer.



Don't eat yellow snow...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top