Results 1 to 4 of 4
I'm a fledgling linux programmer and have created an apparent memory leak. I ran the following code over night (around 250e6 iterations on my machine) and have 'lost' nearly 128MB ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 06-23-2005 #1Just Joined!
- Join Date
- Jun 2005
- Location
- Canada, Halifax
- Posts
- 86
thread memory leak 2.4.26?
I'm a fledgling linux programmer and have created an apparent memory leak. I ran the following code over night (around 250e6 iterations on my machine) and have 'lost' nearly 128MB of RAM. Am I spawning and destroying the threads correctly or have I neglected an important step? I'm running the 2.4.26 kernel with gcc 3.3.4...
Code:#include <stdio.h> #include <stdlib.h> #include <pthread.h> #define CHILDERN 2 int *thread_child(int *pArg); int main(void) { pid_t PPID,PID; pthread_t thread[CHILDERN]; int **pRetPtr; unsigned int i = 0,j = 0,k; PPID = getppid(); PID = getpid(); printf("Root thread start: Parent PID: %i PID: %i\n",PPID,PID); for(;;) { for (k=0;k<CHILDERN;k++) pthread_create(thread+k,NULL,(void *(*)(void *))thread_child,(void *)&PPID); for (k=0;k<CHILDERN;k++) pthread_join(*(thread+k),(void **)pRetPtr); i+=CHILDERN; if((j+=CHILDERN)>10000) { j = 0; printf("%u\n",i); } } printf("Root thread stop: Parent PID: %i PID: %i\n",PPID,PID); exit(0); } int *thread_child(int *pArg) { pid_t PID; int i = *pArg; PID = getpid(); pthread_exit(&PID); }
- 05-24-2006 #2Just Joined!
- Join Date
- May 2006
- Posts
- 2
Hello,
I am facing the exact same issue with same linux kernal version 2.4.26 , gcc version 3.3.3 . Can anybody help me with the reason and the solution?
Thanks
Deepali
- 05-24-2006 #3
Try to monitor your process with top to ensure that is really your program who is leaking and this is not a memory management issue.
Best regards
- 05-24-2006 #4Just Joined!
- Join Date
- May 2006
- Posts
- 2
Thanks for the reply. I have been monitoring the process using top command and the memory consumption has so far been constant (2.8 %) . Still after about 3895445 iterations I recive "out of memory" error during pthread_create() . What other memory issue could this be? My code runs on a embedded system with Linux 2.4.26.
Thanks.
Deepali


Reply With Quote
