Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Fortran95: deallocating arrays necessary in Program and DLL?

Erik_J_
Beginner
268 Views

I understand, that a Fortran 95 program, when ending, gives up all its allocated memory to the system, so no deallocation is necessary and memory leaks cannot occur at that time.

Is this also true for Fortran DLL's called from, f.i., C# at returning to the calling program?

0 Kudos
2 Replies
Steve_Lionel
Honored Contributor III
268 Views

No - that cleanup doesn't happen until image exit. Returning from a procedure, whether it is in a DLL or static library, is not the same.

0 Kudos
Greg_T_
Valued Contributor I
268 Views

Hi Erik,

I have Fortran routines in a DLL called from C#, and I use the "deallocate" command in the Fortran routines to make sure that all local arrays in the Fortran routines have been deallocated before exiting back to the C#.  Deallocating the Fortran arrays allows changes in the C# GUI to the input values so that the Fortran routines can be called again.  Is this what you want to do?  I also avoid using the "stop" command in the Fortran DLL routines as that can freeze the program.  I've found it is better to return an error message or flag from the Fortran DLL to the C# code.

Regards,
Greg T.

0 Kudos
Reply