Re: Leaking pixmaps

Jacques Garrigue <[email protected]>
Newsgroups gmane.comp.lang.ocaml.lib.gtk
Message-ID <[email protected]>
From: Jon Harrop <[email protected]>
> On Wednesday 09 January 2008 12:52:09 Jacques GARRIGUE wrote:
> > From: Jon Harrop <[email protected]>
> >
> > > Has anyone found a bug where using pixmaps causes a memory leak resulting
> > > in X consuming all memory and dying?
> > >
> > > I just ditched pixmaps in favour of direct rendering which fixed the
> > > problem and the symptom deterred me from investigating...
> >
> > This is not a bug, but the normal behaviour since pixmap are on the
> > server side, and it would be complicated to manage them properly.
> > This is the reason there is a Gdk.Pixmap.destroy function, so that you
> > can destroy pixmaps early when you don't need them anymore.
> > examples/timer.ml shows how to use it.
> 
> When using OpenGL from OCaml, I wrapped handles to external resources like 
> display lists and textures in objects and finalized them so OCaml's GC 
> collected the external resource. That worked extremely well but partly 
> because OpenGL does not leak resources after application death as X seems to. 
> Perhaps a similar scheme could be useful here?

Pixmaps are finalized, like all external resources in lablgtk.
But pixmaps can be huge, and you may end up using lots of space before
the GC collects them, so it is better to destroy them explicitly.

> Also, I've managed to reproduce the problem without pixmaps. The
> leak seems to  be with colors now. Can I deallocate a color?

That's rather strange. Colors are allocated on the caml heap
(i.e. they are directly managed by the GC), and only take a few
bytes. I ran your program, but wasn't able to reproduce the
problem (everything works fine). It may be related to a specific color
mode you are using. What is the output of xdpyinfo?

Jacques
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.