From: bierhals AT stud DOT uni-hannover DOT de (Andreas Bierhals) Newsgroups: comp.os.msdos.djgpp Subject: Memory leaks - how do I detect them? Date: Sat, 24 Jan 1998 22:40:15 GMT Organization: RRZN - Newsserver Lines: 86 Message-ID: <34ca6604.28305820@news.rrzn.uni-hannover.de> NNTP-Posting-Host: h14.stud.uni-hannover.de To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hello, I am working on a larger numerical fit program in c++/djgpp-v2 which features a scripting language for user defined output of calculated results. This requires numerous memory allocations using new/delete in order to construct object trees, variable stacks etc. However, I am suspecting the program to have memory leaks and therefore used the functions _go32_dpmi_remaining_virtual_memory() and _go32_dpmi_remaining_physical_memory() (as suggested in this NG before) to show the free memory before and after the construction and destruction of my object tree. While searching for the memory leaks (without success, yet) a problem occured, which can be illustrated with the following test program: // File: test.cc #include #include void showmem(void) { printf("Physical Mem.: %12i Virtual Mem.: %12i\n", _go32_dpmi_remaining_physical_memory(), _go32_dpmi_remaining_virtual_memory() ); } main() { int *array; showmem(); array = new int[100000]; showmem(); delete[] array; showmem(); return 0; } This produced the following output (in a DOS-box under Win95 with about 10 MB of dpmi memory enabled): E:\CPROGS\test>gcc test.cc E:\CPROGS\test>test Physical Mem.: 10092544 Virtual Mem.: 10092544 Physical Mem.: 9502720 Virtual Mem.: 9502720 Physical Mem.: 9502720 Virtual Mem.: 9502720 E:\CPROGS\test>go32-v2 go32/v2 version 2.0 built Aug 12 1996 22:27:23 Usage: go32 coff-image [args] Rename this to go32.exe only if you need a go32 that can run v2 binaries as well as v1 binaries (old makefiles). Put ahead of the old go32 in your PATH but do not delete your old go32 - leave it in the PATH after this one. Set GO32_V2_DEBUG=y in the environment to get verbose output. DPMI memory available: 10239 Kb DPMI swap space available: 0 Kb In the FAQ Chapter 15.x there is mentioned, that free / delete will probably not affect the result of _go32_dpmi_remaining_physical_memory(), because the DJGPP library functions don't release the free'd block back to the system memory. My questions are: - Does this also apply for _go32_dpmi_remaining_virtual_memory() ? - How do I really get the total amount of free memory using the functions in dpmi.h ? - Are there any other methods/tools available, which provide an effective search for memory leaks? (Besides: I used a DJGPP-V2 version which I just (today) have downloaded using the zip-picker from www.delorie.com). Many thanks for help. Andreas Bierhals