08.10.2010 03:27, Marc Lehmann пишет:
On Thu, Oct 07, 2010 at 01:42:12PM +0300, vvvua<[email protected]>  wrote:
I'm trying to handle with possible memory leaks in my project and
have some trouble with exit before timer's callback function starts.
I'm using Linux debian/g++.
So, if I have started 3 timers with custom data and allocation as

     TimeSockMapper *mtm = new TimeSockMapper();
     mtm->repeat = 0;
     mtm->fd.clear();

     ev_timer_init (&(mtm->  tm), heartbeat_cb, 0.001, 0.001);
     ev_timer_start(timeloop,&(mtm->tm));

where "TimeSockMapper" is my custom data block:

struct TimeSockMapper
{
     struct ev_timer tm;
     ev_tstamp repeat;
     ClientID fd;
     void *defPoint;
     TimeSockMapper()
     {
         defPoint = NULL;
     }
};


How can I rise all watchers on a defined "timeloop" to free a memory ?
It's not quite clear to me what you want to know:

If you want to free watcher memory, then that's your job to do once you
stopped the watcher, as libev doesn't manage watcher memory itself.

If you want to free a whole loop (which incidentally stops all watchers) you
can call ev_loop_destroy() on the function.

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.

P.S. small example:
I have created 2 watchers: first with 10 min and the second with 1 hour delay.
Both of them free memory in callback function.
The process is shutting down in 2 min after program starts.
I have to cancel watchers, destroy the loop and free memory.


_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

Reply via email to