- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page