[Top][All Lists]
[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 16:03:28 -0600 |
User-agent: |
Mutt/1.4.2.2i |
I'm sorry, I didn't understand your original question, but I think
I see whats going on now. There is no memory leak here, as a tool
like 'valgrind' will tell you.
The reason you're seeing 19% memory usage in 'top' is because your
OS has not reclaimed the freed memory yet. Some OSes only reclaim
the memory when they need it (or when the program exits).
To verify this, do the following:
compile the program and make 2 copies: prog1 and prog2
Run prog1 and have it do the allocation so you can see 19% in top. Then
have it free the memory.
Run prog2 and have it do the allocation. Run a second instance of prog2
(and a third if you need to). You should see the memory for prog1 drop
to 0% since its being claimed by prog2.
On Wed, Sep 19, 2007 at 02:10:29PM -0600, Sergey Plis wrote:
> Thank you for the reply.
>
> Unfortunately this is not the case. Here is a standard version (no
> curses):
> ------------------------------------------------------------------
> #include <stdio.h>
> #include <gsl/gsl_matrix.h>
> int
> main (void)
> {
> int i, j;
> int c = 5000;
>
> gsl_matrix * m[c];
>
> printf("press any key to allocate matrices...");
> getchar();
>
> for (i = 0; i < c; i++)
> m[i] = gsl_matrix_calloc (100, 100);
>
> printf("press any key to free the memory ...");
> getchar();
>
> for (i = 0; i < c; i++)
> gsl_matrix_free (m[i]);
>
> printf("press any key to exit... ");
> getchar();
>
> return 0;
> }
>
> // compile with :
> // gcc -L/usr/local/lib test.c -lgsl -lgslcblas -lm
> ------------------------------------------------------------------
>
> Here how it looks in sequence of execution:
> 1.
> Program output:
> press any key to allocate matrices...
> Top output:
> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
> 20361 pliz 16 0 3736 580 460 S 0 0.0 0:00.00 a.out
>
> 2.
> Program output:
> press any key to free the memory ...
> Top outputs:
> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
> 20361 pliz 20 0 385m 382m 524 S 0 19.0 0:00.63 a.out
>
> 3.
> Program output:
> press any key to exit...
> Top output:
> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
> 20361 pliz 18 0 385m 382m 536 S 0 19.0 0:00.64 a.out
>
> As you can see it is 385m of memory not de-allocated - not simple
> auxiliary structures.
>
> --
> Sergey
>
Re: [Bug-gsl] memory leak problem with matrices, Sergey Plis, 2007/09/19