@@ -320,10 +320,6 @@ end function initialize_json_file
320
320
!
321
321
! Cast a [[json_value]] pointer and a [[json_core]] object
322
322
! 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.
327
323
328
324
function initialize_json_file_v2 (json_value_object , json_core_object ) &
329
325
result(file_object)
@@ -342,18 +338,34 @@ end function initialize_json_file_v2
342
338
343
339
! *****************************************************************************************
344
340
! > author: Jacob Williams
345
- ! date: 12/9/2013
346
341
!
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
348
354
349
- subroutine json_file_destroy (me )
355
+ subroutine json_file_destroy (me , destroy_core )
350
356
351
357
implicit none
352
358
353
359
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.
354
362
355
363
if (associated (me% p)) call me% json% destroy(me% p)
356
364
365
+ if (present (destroy_core)) then
366
+ if (destroy_core) call me% json% destroy()
367
+ end if
368
+
357
369
end subroutine json_file_destroy
358
370
! *****************************************************************************************
359
371
0 commit comments