PetscHeaderDestroy#
Final step in destroying a PetscObject
Synopsis#
#include <petsc/private/petscimpl.h>
PetscErrorCode PetscHeaderDestroy(PetscObject *obj)
Collective
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#
  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 PetscObjects as it
deallocates the memory for the structure itself:
  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#
Level#
developer
Location#
Examples#
src/ts/tutorials/ex14.c
src/snes/tutorials/ex48.c
Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages