Custom data type with a time watcher and memory control at process exit.

Marc Lehmann schmorp at
Thu Oct 14 06:00:29 CEST 2010

On Fri, Oct 08, 2010 at 11:33:05AM +0300, vvvua <vvvua at> wrote:
> >Or maybe your goal is something else?
> >
> I don't have a list of pointers to watchers. Each watcher frees
> memory when callback function is invoked.
> So I have two ways to free memory:
> 1) Create a list of pointers and free all memory manually when
> destroying a loop.
> 2) Generate events that invoke all registered callbacks using libev.
> Is the second way possible? I understand, that libev doesn't free
> memory allocated by user.

Sorry for the delay..

But yes, you can generate events for all registered watchers, _as long as you
keep the list of registered watchers yourself_, by either using ev_invoke or

You could e.g. use EV_CUSTOM as a flag for the callback(s) to free the
memory. You could, of course also just free it yourself, or call the
callback yourself.

Keep in mind that libev itself might register events, or other parts of
your program, so even if libev had a list, it wouldn't be very helpful.

> The process is shutting down in 2 min after program starts.
> I have to cancel watchers, destroy the loop and free memory.

If the process itself is shutting down (exiting?) then freeing the
watchers is just wasting cpu cycles, the OS does it for you, and much

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_    
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list