Closed borderite closed 3 months ago
I'd be curious to know if the results are any different for this variant:
program test
use json_module
implicit none
call main()
contains
subroutine main()
type(json_file) :: json
call json%initialize()
call json%destroy()
end subroutine main
end program test
I get no leaks for the modified code I show in the previous message.
==12056==
==12056== HEAP SUMMARY:
==12056== in use at exit: 0 bytes in 0 blocks
==12056== total heap usage: 51 allocs, 51 frees, 19,939 bytes allocated
==12056==
==12056== All heap blocks were freed -- no leaks are possible
==12056==
==12056== For lists of detected and suppressed errors, rerun with: -s
==12056== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
I think this is just a case of the compiler not deallocating things at the end of the program (specifically allocatable
variables inside the type). They are deallocated when the types go out of scope (e.g. if they are declared in a subroutine, after the subroutine ends) but I don't think the compilers will do that and the end of the program for some reason. I don't think it really matters.
Note: you can add destroy_core
to your json%destroy()
call to explicitly deallocate those variables:
call json%destroy(destroy_core = .true.)
I use json-fortran with gfortran 12.2.0 on Debian Linux 12 (bookworm). In checking momery leaks of my codes using valgrind, I have noticed that json-fortran leaves unfreed memory at exit. For example, the following simple fortran code results in memory leaks.
I complied this code by
and then ran
The ouput I got is: