[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Memory management



> > I have a few questions about the memory management of libevent.
> >
> > 1) I replaced the memory functions of libvevent using
> > event_set_mem_functions() with my own functions and I added a counter for
> > malloc, realloc and free (Yes, I implemented the special cases realloc(NULL,
> > size) and realloc(ptr, 0)). In my http client, while it is downloading
> > webpages, I noticed that the number of allocations only increases. It stops
> > growing for a while, but then it starts growing up again. When I stop the
> > downloads and execute event_free(base), valgrind shows no memory leak. I
> > believe that the memory is freed only at the end. The problem is that my
> > crawler should never stop downloading and, therefore, the memory usage will
> > always increase.
> >      a) How can I control the memory usage in libevent?
> >      b) I also notice that I can't free a http request, only a http
> > connection. Isn't that the cause of freeing memory being defer?
>
> What allocations seem to be kicking around too long, or growing
> without bounds?  I don't *think* there should be any
> grows-without-bounds stuff in evhttp.  Are you able to tell where the
> memory in question is getting allocated?

The allocations seems to be growing-without-bounds and, consequently,
the memory usage. No, I still did not identified the exact location.
Here's the sequence of commands that I do:

....
if (info->conn)
    evhttp_connection_free(info->conn);
info->conn = evhttp_connection_base_new(base, NULL, IP, PORT);
evhttp_connection_set_timeout(info->conn, 5);
....
info->req = evhttp_request_new(handleRequest, (void *)info);
evhttp_request_set_chunked_cb(info->req, chunkcb);
evhttp_add_header(info->req->output_headers, "Host", info->host);
evhttp_make_request(info->conn, info->req, EVHTTP_REQ_GET, path);
....
evbuffer_remove(_evbuffer, ptr, len);
....

When the request is done, I use the same connection to download
another page from the same host. I do not use evhttp_request_free()
because it always crash my app. By the way, I am using Libevent 2.0.20
over Ubuntu 12.10. Should I use evhttp_request_free()? How?
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.