# PetscGarbageCleanup
Destroys objects placed in the garbage by PetscObjectDelayedDestroy(). 
## Synopsis
```
PetscErrorCode PetscGarbageCleanup(MPI_Comm comm)
```
Collective


## Input Parameters

- ***comm      -*** communicator over which to perform collective cleanup



## Notes
Implements a collective garbage collection.
A per- MPI communicator garbage dictionary is created to store
references to objects destroyed using PetscObjectDelayedDestroy().
Objects that appear in this dictionary on all ranks can be destroyed
by calling PetscGarbageCleanup().


## This is done as follows
1.  Keys of the garbage dictionary, which correspond to the creation
indices of the objects stashed, are sorted.
2.  A collective intersection of dictionary keys is performed by all
ranks in the communicator.
3.  The intersection is broadcast back to all ranks in the
communicator.
4.  The objects on the dictionary are collectively destroyed in
creation index order using a call to PetscObjectDestroy().

This function is intended for use with managed languages such as
Python or Julia, which may not destroy objects in a deterministic
order.




## See Also
 PetscObjectDelayedDestroy()

## Level
developer

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


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/sys/objects/garbage.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)  
