ESMF_RouteHandleDestroy Subroutine

public subroutine ESMF_RouteHandleDestroy(routehandle, keywordEnforcer, noGarbage, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_RouteHandle), intent(inout) :: routehandle
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
logical, intent(in), optional :: noGarbage
integer, intent(out), optional :: rc

Source Code

  subroutine ESMF_RouteHandleDestroy(routehandle, keywordEnforcer, &
    noGarbage, rc)
!
! !ARGUMENTS:
    type(ESMF_RouteHandle), intent(inout)          :: routehandle
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
    logical,                intent(in),   optional :: noGarbage
    integer,                intent(out),  optional :: rc
!
! !DESCRIPTION:
!   Destroys an {\tt ESMF\_RouteHandle}, releasing the resources associated
!   with the object.
!
!   The arguments are:
!   \begin{description}
!   \item[routehandle]
!     The {\tt ESMF\_RouteHandle} to be destroyed.
!   \item[{[noGarbage]}]
!     If set to {\tt .TRUE.} the object will be fully destroyed and removed
!     from the ESMF garbage collection system. Note however that under this
!     condition ESMF cannot protect against accessing the destroyed object
!     through dangling aliases -- a situation which may lead to hard to debug
!     application crashes.
!
!     It is generally recommended to leave the {\tt noGarbage} argument
!     set to {\tt .FALSE.} (the default), and to take advantage of the ESMF
!     garbage collection system which will prevent problems with dangling
!     aliases or incorrect sequences of destroy calls. However this level of
!     support requires that a small remnant of the object is kept in memory
!     past the destroy call. This can lead to an unexpected increase in memory
!     consumption over the course of execution in applications that use
!     temporary ESMF objects. For situations where the repeated creation and
!     destruction of temporary objects leads to memory issues, it is
!     recommended to call with {\tt noGarbage} set to {\tt .TRUE.}, fully
!     removing the entire temporary object from memory.
!   \item[{[rc]}]
!     Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!   \end{description}
!
!EOP
!------------------------------------------------------------------------------
    integer                 :: localrc      ! local return code
    type(ESMF_Logical)      :: opt_noGarbage  ! helper variable

    ! initialize return code; assume routine not implemented
    localrc = ESMF_RC_NOT_IMPL
    if (present(rc)) rc = ESMF_RC_NOT_IMPL

    ! check input variable
    ESMF_INIT_CHECK_DEEP(ESMF_RouteHandleGetInit,routehandle,rc)

    ! Set default flags
    opt_noGarbage = ESMF_FALSE
    if (present(noGarbage)) opt_noGarbage = noGarbage

    ! was handle already destroyed?
    if (routehandle%this .eq. ESMF_NULL_POINTER) then
      if (present(rc)) rc = ESMF_SUCCESS
      return
    endif

    ! Call C++ destroy code
    call c_ESMC_RouteHandleDestroy(routehandle, opt_noGarbage, localrc)
    if (ESMF_LogFoundError(localrc, &
      ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return

    ! nullify pointer
    routehandle%this = ESMF_NULL_POINTER
    ESMF_INIT_SET_DELETED(routehandle)

    ! Return successfully
    if (present(rc)) rc = ESMF_SUCCESS

  end subroutine ESMF_RouteHandleDestroy