HydrologicEngineeringCenter / hec-dss

source code for HEC-DSS (Data Storage System)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

investigate ways to find memory leaks in the JNI code (javaHeclib.dll)

ktarbet opened this issue · comments

Recently we have found some JNI memory leaks in the grid retrieval code.

on windows this code is a possibility

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

I've had success finding some leaks using this in Hec_Zopen:

    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);// | _CRTDBG_MODE_WNDW);
    _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);

and this in Hec_Zclose

   printf("\n calling _CrtDumpMemoryLeaks\n");
   int leaks = _CrtDumpMemoryLeaks();
   if (leaks)
   	printf("\nFound Leaks..");

ref: https://learn.microsoft.com/en-us/visualstudio/debugger/finding-memory-leaks-using-the-crt-library?view=vs-2022

I've had good success using Microsoft's debug memory management for many years.