bug-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gsl] memory leak problem with matrices


From: Patrick Alken
Subject: Re: [Bug-gsl] memory leak problem with matrices
Date: Wed, 19 Sep 2007 11:41:44 -0600
User-agent: Mutt/1.4.2.2i

The problem appears to be in the curses library. If you comment
out all the curses code there is no leak. Libraries like curses
and readline sometimes allocate things the first time you call them
and never deallocate the memory until your program exits. According
to valgrind, the curses library allocated an extra 61,108 bytes
which was not freed when the program exits. This is probably memory
that curses needs to do various tasks and unfortunately the library
does not offer a function call to free this memory before you quit
your program. I know the readline library has the same issue.

Patrick Alken

On Wed, Sep 19, 2007 at 09:53:19AM -0600, Sergey Plis wrote:
> In order to see the memory not being freed compile the following program:
> -------------------------------------------------------------------------
> #include <stdio.h>
> #include <gsl/gsl_matrix.h>
> #include <curses.h>
> int
> main (void)
> {
>   int i, j;
>   int c = 5000;
>   initscr();
>   cbreak();
>   gsl_matrix * m[c];
>   printw("press any key to allocate matrices...");
>   getch();
>   for (i = 0; i < c; i++) 
>     m[i] = gsl_matrix_calloc (100, 100);
>   printw("press any key to free the memory  ...");
>   getch();
>   for (i = 0; i < c; i++) 
>     gsl_matrix_free (m[i]);
>   printw("press any key to exit...             ");
>   getch();
>   endwin();
>   return 0;
> }
> 
> // compile with :
> // gcc -L/usr/local/lib test.c -lgsl -lgslcblas -lm -lcurses
> -------------------------------------------------------------------------
> 
> Run the program and look in the top what is happening to its memory. can be 
> done in a separate terminal window with:
> top -d 1 -p $(ps -A | grep a.out | sed -e 's/^ *//g'|sed -e 's/ .*//g')
> 
> Basically, the memory is not being freed. This is a very strange bug, because 
> for some matrix sizes the memory is freed, for some it is not.
> 
> I have tried this little code snippet at Ubuntu Feisty and Gutsy with the 
> same 
> outcome. Feisty's gsl version is 1.8.3, Gutsy's is 1.9.
> 
> Can this be corrected?
> 
> Thanks!
> 
> --
> Sergey
> 
> 
> _______________________________________________
> Bug-gsl mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/bug-gsl
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]