:orphan: # PetscHeaderDestroy Final step in destroying a `PetscObject` ## Synopsis ``` #include PetscErrorCode PetscHeaderDestroy(PetscObject *obj) ``` ## Input Parameter - ***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 `PetscObject`, `PetscHeaderCreate()` ## Level developer ## Location include/petsc/private/petscimpl.h ## Examples src/snes/tutorials/ex48.c
src/ts/tutorials/ex14.c
--- [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](/manualpages/index.md) [Index of all manual pages](/manualpages/singleindex.md)