Software Archive
Read-only legacy content
17061 Discussions

Memory leak using Windows API GlobalMemoryStatus

hbell
Beginner
341 Views
I wrote the following Windows console program that does nothing except examine the available memory using the Windows API function GlobalMemoryStatus (some of the asterisks are line continuation characters in column 6 and some comment lines need to have the "c" character moved to column 1). I notice that when the resulting executable file is run several times in succession the amount of physical memory available gets progressively less and less. This sounds like a memory leak to me. Question to the forum: What is the source of this memory leak?

use kernel32
use dfwinty
type(T_MEMORYSTATUS) lpMstMemStat
call GlobalMemoryStatus ( lpMstMemStat )
c Specifies a number between 0 and 100 that gives a general idea of current memory utilization, in which 0 indicates no memory use and 100 indicates full memory use.
write(*,*) 'Percent of memory use -> ', lpMstMemStat.dwMemoryLoad
c Indicates the total number of bytes of physical memory.
write(*,*) 'Bytes of physical memory -> ',lpMstMemStat.dwTotalPhys
c Indicates the number of bytes of physical memory available.
write(*,*) 'Bytes of physical memory available -> ',
* lpMstMemStat.dwAvailPhys
c Indicates the total number of bytes that can be stored in the paging file. Note that this number does not represent the actual physical size of the paging file on disk.
write(*,*) 'Bytes that can be stored in the paging file-> ',
* lpMstMemStat.dwTotalPageFile
c Indicates the number of bytes available in the paging file.
write(*,*) 'Bytes available in the paging file -> ',
* lpMstMemStat.dwAvailPageFile
c Indicates the total number of bytes that can be described in the user mode portion of the virtual address space of the calling process.
write(*,*) 'Bytes that can be described in the user mode portion o
*f the virtual address space -> ', lpMstMemStat.dwTotalVirtual
c Indicates the number of bytes of unreserved and uncommitted memory in the user mode portion of the virtual address space of the calling process.
write(*,*) 'Bytes of unreserved and uncommitted memory in the user
* mode portion of the virtual address space -> ',
*lpMstMemStat.dwAvailVirtual
end
0 Kudos
0 Replies
Reply