# PetscHeaderDestroy
Final step in destroying a `PetscObject` 
## Synopsis
```
#include <petsc/private/petscimpl.h>
PetscErrorCode PetscHeaderDestroy(PetscObject *obj)
```

## Input Parameters

- ***h -*** A pointer to the header created with `PetscHeaderCreate()`



## Notes
`h` is freed and set to `PETSC_NULLPTR` when this routine returns.


## Example Usage
```none
  PetscObject obj;

  PetscHeaderCreate(obj, ...);
  // use obj...

  // note pointer to obj is used
  PetscHeaderDestroy(&obj);
```


Note that this routine is the _last_ step when destroying higher-level `PetscObject`s as it
deallocates the memory for the structure itself:
```none
  typedef struct MyPetscObject_s *MyPetscObject;
  struct MyPetscObject_s
  {
    _p_PetscObject  hdr;
    PetscInt       *foo;
    PetscScalar    *bar;
  };

  // assume obj is created/initialized elsewhere...
  MyPetscObject obj;

  // OK, should dispose of all dynamically allocated resources before calling
  // PetscHeaderDestroy()
  PetscFree(obj->foo);

  // OK, dispose of obj
  PetscHeaderDestroy(&obj);

  // ERROR, obj points to NULL here, accessing obj->bar may result in segmentation violation!
  // obj->bar is potentially leaked!
  PetscFree(obj->bar);
```





## See Also
 `PetscHeaderCreate()`

## Level
developer

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/include/petsc/private/petscimpl.h.html#PetscHeaderDestroy">include/petsc/private/petscimpl.h</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex48.c.html">src/snes/tutorials/ex48.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex14.c.html">src/ts/tutorials/ex14.c.html</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/include/petsc/private/petscimpl.h)


[Index of all Sys routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
