Re: [netcdfgroup] netcdf-4 memory leak

Jeff Whitaker wrote:
Hi all:

I found a memory leak, either in the netcdf-4 or HDF5 libs. To reproduce it, run the simple_xy_wr.c example program to create a file, then open and close it in a loop, monitoring the memory usage with top. If the file is created in netcdf-3 (or netcdf-4 classic) format, the memory usage remains constant. If the file is created in NETCDF4 format, the memory usage goes up and up. Here's the simple program to trigger the leak. I've attached simple_xy_4.nc and simple_xy_3.nc - the former will lead to a leak, the latter will not.


#include <stdlib.h>
#include <stdio.h>
#include <netcdf.h>

/* This is the name of the data file we will read. * Change to simple_xy_3.nc and leak will disappear*/
#define FILE_NAME "simple_xy_4.nc"

/* Handle errors by printing an error message and exiting with a
* non-zero status. */
#define ERRCODE 2
#define ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);}

int
main()
{
int ncid,retval,i;

  for (i=0; i<1000000; i++)
     {
  /* Open the file. NC_NOWRITE tells netCDF we want read-only access
   * to the file.*/
  if ((retval = nc_open(FILE_NAME, NC_NOWRITE, &ncid)))
     ERR(retval);

  /* Close the file, freeing all resources.   ????  */
  if ((retval = nc_close(ncid)))
     ERR(retval);
     }

  return 0;


BTW:  I'm using netcdf-4.0 and HDF5 1.8.1.

-Jeff


Replying to myself, just to make sure this hasn't fallen off the radar screen. Ed - do you think it's an HDF5 library issue?

-Jeff

--
Jeffrey S. Whitaker         Phone  : (303)497-6313
Meteorologist               FAX    : (303)497-6449
NOAA/OAR/PSD  R/PSD1        Email  : Jeffrey.S.Whitaker@xxxxxxxx
325 Broadway                Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web    : http://tinyurl.com/5telg



  • 2008 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: