Silverfrost Forums

Welcome to our forums

Neverending Memory Grow.!! It seems deallocate doesn`t release memory.

25 Feb 2005 5:30 #113

Hi all,

I have a serious problem with memory. Hope anyone can help me.This is what happens:

In my application, there are many arrays (large arrays,i.e real*4 array(60000,180)). Besides, these arrays are passed as arguments among the diferent subroutines. And what is the worst...these subroutines can be called too many times (80000 - 100000 times aprox).

At the beggining, I used these arrays as static (I had only used Fortran77 until this application). The consequences were that after a time of execution I got stack overflow. Then, using ftn95 advantages, I used allocatable arrays and pointers to pass them as arguments, and deallocate to avoid the overflow. Now I do not have stack overflow.

However, if I use the Window Task Manager(Ctrl+Alt+Spr) and see the performance tab, the memory increases and doesn´t stop. The program works o.K but it seems it doesn´t release memory, and in some cases, if I have large arrays the program 'cracks'. Now I have defined all the variables, arrays as dynamic, but memory still grows. Anyway, and tell me if I am wrong, the local variables are supposed to be released when subroutines end. And when a 'deallocate(array)', the memory is also suposed to be released. In my program, the memory is only released when the program is exited.

If this can help you..I am using .NET platform (a c# program, and I call the fortran routine from c#). Is there garbage collector in FTN95, is my problem diferent. In the other side, I have read the previous thread about editbin, but I am not sure if is the same problem as mine.

Sorry by the large writting but I think it was necessary. It is difficult to explain. Thanks a lot. Regards Roberto

25 Feb 2005 1:16 #114

Are you compiling the project in CheckMate mode? If so, because of the way CheckMate works, new memory is used in preference to reusing released memory until the physical memory is exhausted, then released memory is reused. This ensures that variable checking can be done accurately. If you are compiling/running as CheckMate try changing to Debug and see if the problem persists. If this does not solve your issue it may be a programming error, if you post an working example of the code that is behaving this way someone may be able to help more - please keep the example as small as possible.

28 Feb 2005 1:05 #116

Thanks Andrew for your quick answer.

I am compiling in debug mode (no in CheckMate mode). Here you have an example of the code I am using. I have summed it up to make it clear. Basically,I have tried to show the way I am allocating memory and passing arguments (as pointers) between subroutines.

! Stub to call the this fortran routines from C#

SUBROUTINE ANALYSIS_STUB(NM, ERROR)

  ASSEMBLY_INTERFACE (NAME='Analysis')
    
    
    INTEGER*1     NM
    INTEGER*1     ERROR(:)
        
  CALL ANALYSIS(NM,ERROR)

  ENDSUBROUTINE
  

  SUBROUTINE ANALYSIS(NM, ERROR)

   ! interface to be able to pass pointers as arguments
   INTERFACE

    SUBROUTINE My_Subroutine(matrix,NPOINT,temp_matrix,
 #                     NM, ERROR)
        
	        real*4,pointer::matrix(:,:)
	    
        INTEGER*4,pointer::NPOINT
        INTEGER*1,pointer::NM
       
        INTEGER*1,pointer::temp_matrix(:)
                    INTEGER*1,pointer:: ERROR(:)

    END SUBROUTINE My_Subroutine  
    

    END INTERFACE
    
  !Variables Declaration
   
    INTEGER*2     N_BLOQUE

    ! Targets
    INTEGER*1,target:: NM 
    INTEGER*1,target:: ERROR(10)	  
    INTEGER*4,target::NTEMP 
   
  ! Dynamic Arrays       

    REAL*4, ALLOCATABLE::  matrix(:,:)  
    INTEGER*1,ALLOCATABLE::temp_matrix(:)	          
    
  ! Pointers
    REAL*4,pointer::p_matrix(:,:)
    INTEGER*1,pointer::p_temp_matrix(:)
    INTEGER*4,pointer::p_ntemp
    
   
    ALLOCATE (matrix(60000,180))    
    

    p_matrix=>matrix
    p_ntemp=>ntemp
    

   DO 30 i=1,60000 
        ALLOCATE(temp_matrix(20000))
        p_temp_matrix=>temp_matrix
        temp_matrix(M)=2      
        CALL My_Subroutine(p_matrix,p_ntemp,p_temp_matrix,pERROR)
        deallocate(temp_control)

30 continue deallocate(temp)

900 END

! The body of My_Subroutine has not been included in order to not complicate the example.

28 Feb 2005 1:12 #117

Sorry, when I tried to make the code clearer, I made a mistake in the line I have now put in bold and big font. Sorry for the confussion 😦(

! Stub to call the this fortran routines from C#

SUBROUTINE ANALYSIS_STUB(NM, ERROR)

ASSEMBLY_INTERFACE (NAME='Analysis')

INTEGER1 NM INTEGER1 ERROR(:)

CALL ANALYSIS(NM,ERROR)

ENDSUBROUTINE

SUBROUTINE ANALYSIS(NM, ERROR)

! interface to be able to pass pointers as arguments INTERFACE

SUBROUTINE My_Subroutine(matrix,NPOINT,temp_matrix,

NM, ERROR)

real*4,pointer::matrix(:,:)

INTEGER4,pointer::NPOINT INTEGER1,pointer::NM

INTEGER1,pointer::temp_matrix(:) INTEGER1,pointer:: ERROR(:)

END SUBROUTINE My_Subroutine

END INTERFACE

!Variables Declaration

INTEGER*2 N_BLOQUE

! Targets INTEGER1,target:: NM INTEGER1,target:: ERROR(10) INTEGER*4,target::NTEMP

! Dynamic Arrays

REAL4, ALLOCATABLE:: matrix(:,:) INTEGER1,ALLOCATABLE::temp_matrix(:)

! Pointers REAL4,pointer::p_matrix(:,:) INTEGER1,pointerp_temp_matrix(:) INTEGER*4,pointerp_ntemp

[big]integer*1,pointer::p_error(:)[/big]

ALLOCATE (matrix(60000,180))

p_matrix=>matrix p_ntemp=>ntemp [big]p_error=>error[/big]

DO 30 i=1,60000 ALLOCATE(temp_matrix(20000)) p_temp_matrix=>temp_matrix temp_matrix(M)=2 CALL My_Subroutine(p_matrix,p_ntemp,p_temp_matrix,p_ERROR)

[big]deallocate(temp_matrix)[/big]

30 continue deallocate(temp)

900 END

28 Feb 2005 1:16 #118

The last one!!!. I am a dissater. The administrator is going to kill me. Soooooorrry

Sorry, when I tried to make the code clearer, I made a mistake in the line I have now put in bold and big font. Sorry for the confussion

! Stub to call the this fortran routines from C#

SUBROUTINE ANALYSIS_STUB(NM, ERROR)

ASSEMBLY_INTERFACE (NAME='Analysis')

INTEGER1 NM INTEGER1 ERROR(:)

CALL ANALYSIS(NM,ERROR)

ENDSUBROUTINE

SUBROUTINE ANALYSIS(NM, ERROR)

! interface to be able to pass pointers as arguments INTERFACE

SUBROUTINE My_Subroutine(matrix,NPOINT,temp_matrix,

NM, ERROR)

real*4,pointer::matrix(:,:)

INTEGER4,pointer::NPOINT INTEGER1,pointer::NM

INTEGER1,pointer::temp_matrix(:) INTEGER1,pointer:: ERROR(:)

END SUBROUTINE My_Subroutine

END INTERFACE

!Variables Declaration

INTEGER*2 N_BLOQUE

! Targets INTEGER1,target:: NM INTEGER1,target:: ERROR(10) INTEGER*4,target::NTEMP

! Dynamic Arrays

REAL4, ALLOCATABLE:: matrix(:,:) INTEGER1,ALLOCATABLE::temp_matrix(:)

! Pointers REAL4,pointer::p_matrix(:,:) INTEGER1,pointerp_temp_matrix(:) INTEGER*4,pointerp_ntemp integer*1,pointer::p_error(:)

ALLOCATE (matrix(60000,180))

p_matrix=>matrix p_ntemp=>ntemp p_error=>error

DO 30 i=1,60000 ALLOCATE(temp_matrix(20000)) p_temp_matrix=>temp_matrix temp_matrix(M)=2 CALL My_Subroutine(p_matrix,p_ntemp,p_temp_matrix,p_ERROR) deallocate(temp_matrix) 30 continue

deallocate(matrix)

900 END

28 Mar 2005 11:46 #131

Thanks a lot Paul,

Finally, I translated it into c# so the garbage collector cares about memory release. Anyway it is important for other people to know about that bug. I will take it into account for the next time and with the full new FTN95 release.

Thank you again.

Please login to reply.