0

I tried adding images to my conky.lua with the following function

function drawimage(cr,img)
    image = cairo_image_surface_create_from_png (img)
    cairo_set_source_surface (cr, image, screen.x, screen.y)
    cairo_paint (cr)
    cairo_surface_destroy (image)
end

After starting conky my pc took a few minutes to get frozen. After a reboot, I realized that cairo_image_surface_create_from_png() function that eats my ram memory.

How can I prevent that, if possible?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Yunus
  • 1,634
  • 2
  • 13
  • 19
  • presumably there's not a memory leak in the function and it needs the memory to do the work you've asked it to do? It's not clear to me what the appropriate response would be here. – Jeff Schaller Jun 09 '19 at 11:34

1 Answers1

0

My guess is that the memory isn't released until conky closes or when the configuration is reloaded.

Instead of creating the surface on each call to drawimage, you could make a function x that creates the surface and a function y that destroys the surface, call x from lua_startup_hook, and call y from lua_shutdown_hook. That way, the surface would only be created once at Conky startup or config reload and destroyed once at Conky shutdown or config reload.

See man conky for details on lua_startup_hook and lua_shutdown_hook.

David Yockey
  • 1,653
  • 7
  • 12