Recently large data sets were causing stack overflows in a program of mine. To allow for larger temporary arrays (prevent stack overflows), I changed Fortran>Optimization>Heap Arrays from <blank> to 0 (see attached memsetting.jpg).
After this change my program was using up all available memory to the point where ALLOCATE would fail. Also i was able to see the memory used up in task manager.
I built a test program to verify what i was seeing:
REAL*8, ALLOCATABLE, DIMENSION(:) :: allocarray
INTEGER, INTENT(in) :: n
REAL*8, INTENT(inout), DIMENSION(n) :: array
REAL*8, DIMENSION(n) :: localarray
localarray = 1.D0
DO i = 1,n
array(i) = -DBLE(i)
array = array + localarray
If i set "Heap Arrays" to blank, Inspector does not detect any problems.
If i set "Heap Arrays" to 0, Inspector detects a memory leak:
ID Problem Sources Modules Object Size State
P1 Memory leak memsub.f90 memtest.exe 80 New
If i set "Heap Arrays" to 0, and change my local variable "localarray" to allocatable (and deallocate it at the end of the subroutine), Inspector does not detect any problems.
The Inspector results agree with what i was seeing in my program as far as memory usage.
My conclustion is that explicitly declared temporary arrays (not sure if that is the correct term, for example: REAL*8, DIMENSION(n) :: localarray) do not get automatically freed when they are created on the heap like i assumed they were.
Is this common knowledge? I didn't pick this up from reading posts about stack vs heap.
I guess I will stop using "Heap Arrays = 0" and try increasing the stack size to hopefully cure my issues? I have no idea what the stack size should be. Is there a way to tell what the default stack size is?