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: Sergey Plis
Subject: Re: [Bug-gsl] memory leak problem with matrices
Date: Wed, 19 Sep 2007 20:07:45 -0600

May be you're right - it has to do with the OS (Linux, kernels tried
2.6.22,2.6.20,2.6.18). I have tried running about 7 copies of the
program. Each allocating (but not initializing) 2Gb of virtual memory on
a machine that has just 2Gb of physical memory. None has freed any of it
until it exited. I've tried initializing the memory and the machine just
swaps when I run the next program. And this is after everything was
freed in the previous copy.

Plus, this code just works as it should:
#include <stdio.h>
int
main (void)
{
  int i, j, k;
  int c = 10000;
  char * m[c];

  printf("press any key to allocate matrices...");
  getchar();
  // allocate the matrices
  for (i = 0; i < c; i++) 
    m[i] = malloc(100*100*8);
  // write to the memory
  // initialize the matrices
  for (k = 0; k < c; k++) 
    for (i = 0; i < 100*100*8; i++)
      m[k][i] = 'a';
  printf("press any key to free the memory  ...");
  getchar();
  for (i = 0; i < c; i++) 
    free (m[i]);
  printf("press any key to exit...             ");
  getchar();
  return 0;
}

Bottomline:
There is a problem - memory does not get deallocated! and thus cannot be
reclaimed. The simple example to demonstrate this is provided in my
previous emails. In a serious project running for long time that is a
disaster. Though, it needs to be determined where the trouble comes
from.

Thanks for the prompt reaction!

--
Sergey





reply via email to

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