# PetscObjectRegisterDestroy
Registers a PETSc object to be destroyed when `PetscFinalize()` is called. 
## Synopsis
```
#include "petscsys.h"    
PetscErrorCode PetscObjectRegisterDestroy(PetscObject obj)
```
Logically Collective on obj


## Input Parameter

- ***obj -*** any PETSc object, for example a `Vec`, `Mat` or `KSP`.
This must be cast with a (`PetscObject`), for example,
`PetscObjectRegisterDestroy`((`PetscObject`)mat);





## Note
This is used by, for example, PETSC_VIEWER_XXX_() routines to free the viewer
when PETSc ends.


## See Also
 `PetscObjectRegisterDestroyAll()`

## Level
developer

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/objects/destroy.c.html#PetscObjectRegisterDestroy">src/sys/objects/destroy.c</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/sys/objects/destroy.c)


[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)  
