# Is conky leaking memory?



## jrm@ (Jun 2, 2011)

After about a day of running, conky uses over 300M of memory.

Install details: 

```
conky --version
Conky 1.8.1 compiled Wed Apr  6 16:25:44 ADT 2011 for FreeBSD 8.2-RELEASE (i386)

Compiled in features:

System config file: /usr/local/etc/conky/conky.conf
Package library path: /usr/local/lib/conky

 X11:
  * Xdamage extension
  * XDBE (double buffer extension)
  * Xft
  * ARGB visual

 Music detection:
  * MOC

 General:
  * math
  * Curl
  * Weather (METAR)
  * Weather (XOAP)
  * config-output
  * iostats
  * ncurses
  * Lua

  Lua bindings:
```

~/.conkyrc:

```
alignment bottom_left
background no
border_inner_margin 0
#border_margin 9
border_outer_margin 0
border_width 1
default_color darkgrey
default_outline_color DarkGrey
default_shade_color black
double_buffer yes
draw_borders no
draw_outline no # amplifies text
draw_shades yes
gap_x 100
gap_y 24
lua_load ~/.conky_lua_scripts.lua
maximum_width 1680
minimum_size 1680 # use horizontal resolution of monitor
no_buffers no
own_window yes
own_window_hints undecorate,sticky,skip_taskbar,skip_pager # NB: normally, below is used here, but we don't want that for our panel
own_window_transparent yes
own_window_type dock
short_units yes
stippled_borders 0
update_interval 1.0
uppercase no
use_spacer right
use_xft yes
#xftfont Bitstream Vera Sans Mono-7
xftfont Andale Mono-9
#xftfont Clean-8
#xftfont cubicfive10:pixelsize=8
#xftfont squaredance10:pixelsize=14
#xftfont swf!t_v02:pixelsize=10
xftalpha 1
TEXT
${color #FFFFFF}$nodename_short \
${color #707070}| ${color #FF9900}UP${color #707070}:$uptime_short \
| ${color #FF9900}CPU${color #707070} ${color #FF9900}1${color #707070}:${lua_parse pad3 ${cpu cpu1}}% ${color #FF9900}2${color #707070}:${lua_parse pad3 ${cpu cpu2}}% ${color #FF9900}3${color #707070}:${lua_parse pad3 ${cpu cpu3}}% ${color #FF9900}4${color #707070}:${lua_parse pad3 ${cpu cpu4}}% (${lua_parse pad3 ${cpu cpu0}}%) \
| ${color #FF9900}MEM${color #707070}:${mem}/${memmax} ($memperc%) \
| ${color #FF9900}SWP${color #707070}:${swap}/${swapmax} ($swapperc%) \
| ${color #FF9900}WTR${color #707070}:${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ CYHZ temperature 5}C ${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ CYHZ cloud_cover 5} ${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ CYHZ wind_speed 5}km/h ${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ CYHZ wind_dir 5} ${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ CYHZ humidity 5}% \
| ${color #FFFFFF}${time %a %b %d %G %H:%M %S %Z}
${color #FF9900}/${color #707070}:${fs_used /}/${fs_size /} (${fs_used_perc /}%) \
| ${color #FF9900}/tmp${color #707070}:${fs_used /tmp}/${fs_size /tmp} (${fs_used_perc /tmp}%) \
| ${color #FF9900}/usr${color #707070}:${fs_used /usr}/${fs_size /usr} (${fs_used_perc /usr}%) \
| ${color #FF9900}/var${color #707070}:${fs_used /var}/${fs_size /var} (${fs_used_perc /var}%) \
| ${color #FF9900}DSK${color #707070}:${diskio_read} / ${diskio_write} \
| ${color #FF9900}NET${color #707070}:${upspeed re0} / ${downspeed re0} \
| ${color #FF9900}VOL${color #707070}: $mixer
```

.conky_lua_scripts.lua:

```
function conky_pad2( number )
    return string.format( '%2u' , conky_parse( number ) )
end

function conky_pad3( number )
    return string.format( '%3u' , conky_parse( number ) )
end

function conky_pad31( number )
    return string.format( '%5.1f' , conky_parse( number ) )
end

function conky_pad4( number )
    return string.format( '%4u' , conky_parse( number ) )
end

function conky_pad41( number )
    return string.format( '%6.1f' , conky_parse( number ) )
end
```

Here is a screenshot:






Is conky sucking up memory like this for anyone else?


----------



## astralfx (Jun 2, 2011)

I don't know why you have 5 almost identical statements. Why not just use variables, and then have only 1 statement, which would be much easier to work with 

However if your not going to combine your statements, you can do this trick anyway, just add this before every END statement.


```
cairo_surface_destroy(cs)
cairo_destroy(cr)
```
It destroys the drawing surface after each iteration and releases the memory..

Hope this fixes your memory leaks


----------



## jrm@ (Jun 2, 2011)

Thanks for your reply.  By the "5 almost identical statements", I'm assuming you mean the lua functions.  I'm actually only using one of those functions (pad3) for the cpu percentages, because they ignore the use_spacer option in ~/.conkyrc.  Without this, the entire conky screen moves right/left whenever an extra digit is needed (e.g. going from x% cpu usage to xx%).  In any case, I've run conky without the cpu percentages and lua scripts and the memory problems persist.


----------



## astralfx (Jun 2, 2011)

Hmmm, it's probably something in the initial declaration of Conky. I noticed in mine it has "no_buffers yes" instead of "no" as yours.

And I suffer no memory leaks, it run's at around 1%, and memory is around a few MB's, and drops every so often, but then again my conky script is tiny, since I used to have all that fancy memory-monitoring functions, but after using it for 2 years, it became useless to me, I only ever looked at it rarely (the HD space, RAM, fancy clock, OS, kernel etc..), it just wasted CPU cycle for eye-candy.

So I removed everything apart from what I always used. Now I have such a simple conky, which is minimal and perfect for me, and takes a tiny space in the bottom-left screen (I always use the CPU bar, habit of looking at it all the time, and I can't be bothered to look at multiple core CPU, so better to use the average) 







Anyway here's my initial declarations, might help you:


```
##      .conkyrc configuration
alignment bottom_left
background yes
color0 555555                   #

#----Temperature colors----
color4 58ACFA   #cool
color5 FFCC00   #warm
color6 CC0000   #hot

color2 00B4F0                   #middle light-blue
color3 slate grey               #gray..

cpu_avg_samples 2               #time in (s)
default_color a7afc3            
default_outline_color 000000    # Black
default_shade_color 000000      # Black
double_buffer yes 
draw_borders no
draw_outline no  
draw_shades no
gap_x 1
gap_y 0
max_specials 1024
max_user_text 10000
#maximum_width 500 500
#minimum_size 500
net_avg_samples 2
no_buffers yes
override_utf8_locale yes
own_window yes
own_window_colour 000000        # Black
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
own_window_transparent yes
own_window_type override        ## normal
pad_percents 2                  # to co nizej, miejsc po przecinku
short_units yes                 # krotka wersja podawania wielkosci dyskow np. 612.21M/3.$
stippled_borders 3
text_buffer_size 8000
update_interval 1.0
uppercase yes
use_spacer right
draw_graph_borders yes
...
```


----------



## vermaden (Jun 2, 2011)

From what I remember, *conky* has memory leak when you are using any of the diskio options.


----------



## jrm@ (Jun 3, 2011)

Thanks again for your responses.  @vermaden, it looks like it was the diskio stuff.  I disabled that before leaving for home yesterday and *conky* is now using about 8Mb now.

It's too bad.  The diskio was nice because my case is located where I can't easily see the disk lights.


----------



## shitson (Jun 3, 2011)

To fix the problem on my computer I run the following. This script just kills all my conky processes, then starts them again.


```
#!/bin/sh

#
# Env variables for X & conky
#

export DISPLAY=:0.0

#
#	Kill, Start Conky
#	Due to the terrible
#	memory leak in program
#

kill -9 `pgrep conky`
/usr/local/bin/conky &
/usr/local/bin/conky -c ~/.conkyrc_log &
```

Add the following (with the correct directory path) to crontab to make this action happen every 2 hours. 


```
0 */2 * * * ~/keep_alive/reset_conky.sh 2>/dev/null
```


----------

