Wednesday, July 11, 2012

Xvfb Memory Leak Workaround

I've been using Xvfb, the X virtual frame buffer, for a few projects. Xvfb allows you to run applications that require a display, without actually having a graphics card or a screen. I started noticing that the resident memory used by the Xvfb process would continually go up. I could literally run processes that connect to the display in a loop and watch the memory grow. Clearly, there was some kind of memory leak going on.

I finally found a workaround to preventing this memory issue. If you add -noreset to the argument of Xvfb, the memory issue vanishes. By default, when the last client to Xvfb disconnects, the server resets itself. My guess is that this works fine when video memory is backed by a hardware device, but Xvfb has a bug where it doesn't free the memory it allocated for the buffer. By setting the noreset option, the server no longer restarts and the memory isn't lost.

Here's my Xvfb command line:
Xvfb :1 -screen 0 1024x768x24 -ac +extension GLX +render -noreset

An explanation of the other arguments:

  • :1 - Runs the server on "display 1". Most X servers run on display 0 by default.
  • -screen 0 1024x768x24 - Sets screen 0 (the default screen) to a resolution of 1024x768 with 24 bits per pixel.
  • -ac - Disables access control because X access control is incredibly painful to get right, and since the server is usually only accessible from localhost, it's not a big deal.
  • +extension GLX - Enables the OpenGL extension, allowing graphics programs that use OpenGL to work inside the virtual display.
  • +render - Enables the X Rendering extension, enabling advanced image compositing features that most applications will need.
I also use a simple Xvfb start script. It's available as a gist.


  1. Thanks that helped me out!



    1. - Cực Viêm Chi Địa, Hắc Ám Thần Điện cũng sẽ đến.

      Một âm thanh Âm Lệ từ đàng xa truyền đến, đó là thanh âm của Lam Ma.

      - Thanh Sơn, ngươi tựa hồ cũng đến rồi, gặp người quen ngươi không bắt chuyện sao.

      Trần Đào nhìn về phía bên ngoài nói.

      - Trần Đào, chúng ta là người quen cũ, không nghĩ tới ngươi người còn chưa chết saodongtam
      mu moi ra hom nay
      tim phong tro
      nhac san cuc manh
      tổng đài tư vấn luật
      văn phòng luật hà nội
      tổng đài tư vấn luật
      thành lập công ty trọn gói
      chém gió
      trung tâm ngoại ngữ.

      Thanh âm của Thanh Sơn từ trong sơn mạch truyền đến, Thanh Sơn với Trần Đào rất quen biết.

      - Trần Đào đại nhân, Thanh Sơn Lão Tổ đã gia nhập Hắc Ám Thần Điện, trở thành Hắc Ám Thần Điện Cửu Thiên Tôn, hai tháng trước Hắc Ám Thần Điện cùng Toan Nghê Tộc, Viễn Cổ Minh Xà Tộc, Viễn Cổ Hổ Tộc và Thần Phượng Tộc liên thủ công kích Thần Hoàng Tộc kết giới, kết

  2. Well work!Thanks

    1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.

  3. Hi Jeff, good blog!

    I tell him that I tried to run the service with the parameter "-noreset", also without, and in all cases the memory grows indefinitely, the only way I found is to stop and restart the program running.

    I run it as follows: Xvfb :1 -screen 0 1x1x24 -dpi 96 -noreset &

    For more information, run Vvfb process, then export the DISPLAY variable and finally start an instance of tomcat over Ubuntu.

    I searched and tried, but still can not find any solution to this problem.

    Can guide me what else I can try?

    Thank you very much.

  4. If you run Xvfb with -noreset, start the tomcat server, let the memory grow, and then kill the tomcat server, does the Xvdb memory go back down?

    If so, then there is a memory leak in tomcat, not Xvfb.

  5. thanks for replying,

    I tell him that to stop the tomcat, xvfb memory remains the same, is not released.
    I'm thinking it may be a problem in the coding, and not in freeing the resources used (is an application made ​​with Java and SWT).

  6. How do you do multiple extensions? Like +extension RANDR GLX? Also I'm using xvfb-run. How would you convert the Xvfb command to xvfb-run?

    1. Because I'm currently getting this error: Xlib: extension "RANDR" missing on display ":1". When running xvfb-run. Even when I use something like: xvfb-run --auto-servernum --server-num=1 --server-args="-noreset +extension RANDR" slimerjs robot.js

  7. I think you made awesome decision the moment when you choose this topic of the blog article here. Very usefull informatiom
    access Abmp3 in UK