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)

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?

  • 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 9 '19 at 11:34

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.