Thomas Hruska <[EMAIL PROTECTED]> wrote:
> Ananth wrote:
> > Andreanes Yosef Vanderlee <[EMAIL PROTECTED]> wrote:
> >> Hi... I have a problem with this code:
> >> ----------------------------------------------------------
> >> do{
> >> delay(1500); /* if I remove this, memory usage will grown so fast */
> >> close(tcp_socket);
> >> tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
> >> ret2 = connect(tcp_socket, (struct sockaddr*)&peer, sizeof(peer));
> >> }while(ret2 != 0);
> >> ----------------------------------------------------------
> >>
> >> that part of code will try to connect to server as long as the server
> >> is still down.
> >>
> >> My problem is, if I remove delay there, memory usage will grown very
> >> fast, so does the CPU usage (in 1 tested pc, it hang).
> >>
> >> But if I put that delay, the CPU usage is not high, but the memory
> >> usage is still going bigger n bigger as long as the server is down.
> >>
> >> I try to put that delay, and cut the connection to the server (so that
> >> it'll always run that part of my code) for about 1 hour, and the
> >> memory usage is growing from 1.8MB to 6.8MB.
> >>
> >> Should I put something on my code to refresh the memory?
> >
> > I had this problem in one of my projects in the past, CPU shooting to 100%.
> > I put in a Sleep(100) and that solved the problem.
> > Don't know if there's a better way, but the Sleep solved my issues.
> >
> > Cheers
> > - Ananth
>
> Ananth: Read the problem carefully. The OP is experiencing a memory
> allocation/growth issue NOT a performance issue.
eep! My bad. I thought OP had 2 questions: (1) whether Sleep was okay
to use, and (2) memory leak.
Shot a reply just before leaving from work, should not do that again.
Cheers
- Ananth