Skip to content

Commit 007020b

Browse files
committed
added ability to destroy json_core in a json_file using json_file_destroy.
1 parent 8d94004 commit 007020b

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/json_file_module.F90

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,6 @@ end function initialize_json_file
320320
!
321321
! Cast a [[json_value]] pointer and a [[json_core]] object
322322
! as a [[json_file(type)]] object.
323-
!
324-
!@note [[initialize_json_core]], [[json_initialize]],
325-
! [[initialize_json_core_in_file]], and [[initialize_json_file]]
326-
! all have a similar interface.
327323

328324
function initialize_json_file_v2(json_value_object, json_core_object) &
329325
result(file_object)
@@ -342,18 +338,34 @@ end function initialize_json_file_v2
342338

343339
!*****************************************************************************************
344340
!> author: Jacob Williams
345-
! date: 12/9/2013
346341
!
347-
! Destroy the [[json_file(type)]].
342+
! Destroy the [[json_value]] data in a [[json_file(type)]].
343+
! This must be done when the variable is no longer needed,
344+
! or will be reused to open a different file.
345+
! Otherwise a memory leak will occur.
346+
!
347+
! Optionally, also destroy the [[json_core]] instance (this
348+
! is not necessary to prevent memory leaks, since a [[json_core]]
349+
! does not use pointers).
350+
!
351+
!### History
352+
! * 12/9/2013 : Created
353+
! * 4/26/2016 : Added optional `destroy_core` argument
348354

349-
subroutine json_file_destroy(me)
355+
subroutine json_file_destroy(me,destroy_core)
350356

351357
implicit none
352358

353359
class(json_file),intent(inout) :: me
360+
logical,intent(in),optional :: destroy_core !! to also destroy the [[json_core]].
361+
!! default is to leave it as is.
354362

355363
if (associated(me%p)) call me%json%destroy(me%p)
356364

365+
if (present(destroy_core)) then
366+
if (destroy_core) call me%json%destroy()
367+
end if
368+
357369
end subroutine json_file_destroy
358370
!*****************************************************************************************
359371

0 commit comments

Comments
 (0)