Destructor routine for a json_value pointer. This must be called explicitly if it is no longer needed, before it goes out of scope. Otherwise, a memory leak will result.
Destroy the json_value pointer before the variable goes out of scope:
subroutine example1() type(json_value),pointer :: p call json_create_object(p,'') call json_add(p,'year',2015) call json_print(p) call json_destroy(p) end subroutine example1
Note: it should NOT be called for a json_value pointer than has already been added to another json_value structure, since doing so may render the other structure invalid. Consider the following example:
subroutine example2(p) type(json_value),pointer,intent(out) :: p type(json_value),pointer :: q call json_create_object(p,'') call json_add(p,'year',2015) call json_create_object(q,'q') call json_add(q,'val',1) call json_add(p, q) !add q to p structure ! do NOT call json_destroy(q) here, because q is ! now part of the output structure p. p should be destroyed ! somewhere upstream by the caller of this routine. nullify(q) !OK, but not strictly necessary end subroutine example2
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(json_value), | intent(inout), | pointer | :: | me | ||
logical(kind=LK), | intent(in), | optional | :: | destroy_next | if true, then me%next is also destroyed (default is true) |
Destroy a json_value linked-list structure.