Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
6 Views

Memory leaks in Fortran dlls

When Intel Fortran quits a program it tidies up after itself so there are no memory leaks. It seems to do this very well.

What happens with dlls? When I exit a Fortran dll that I have written, do I need to be careful to clean up, especially deallocating allocatable arrays or is this done for me?

 

0 Kudos
2 Replies
Highlighted
6 Views

When an executable exits, the

When an executable exits, the operating system automatically frees all allocated memory. You don't have to do this. The Intel Fortran run-time library does establish an exit handler than closes open files. There isn't anything that explicitly deallocates on exit.

There isn't really such a thing as "exiting" a DLL. A DLL is just a library of routines. You can establish a routine to be called when the DLL is unloaded, but that is unusual in a normal application. If you call a Fortran routine that allocates an ALLOCATABLE, if it is a local variable to the routine it will get deallocated when that routine exits. But memory used for I/O operations, and allocated POINTERs, will remain allocated across calls. (Local POINTERs will, of course, become undefined but any memory allocated to them will remain allocated.

Retired 12/31/2016
0 Kudos
New Contributor III
6 Views

I've had good success

I've had good success deallocating local arrays at the end of routines in DLLs.  It sounds like the deallocation may not be totally necessary, but it doesn't add much effort or extra code when writing the routine.  I feel that it also helps with error trapping when an invalid input has been given, it can be caught, a message returned to the user.  Without exiting the program the input can be changed and the analysis run again calling the routines in the DLL.  I've found it can also help to use the options in the allocate command to check if there is a problem allocating the local arrays, rather than having the program crash.

Regards,
Greg

0 Kudos