# PetscMallocDump
Dumps the currently allocated memory blocks to a file. The information printed is: size of space (in bytes), address of space, id of space, file in which space was allocated, and line number at which it was allocated. 
## Synopsis
```
#include "petscsys.h" 
PetscErrorCode PetscMallocDump(FILE *fp)
```
Not Collective


## Input Parameter

- ***fp  -*** file pointer.  If fp is NULL, stdout is assumed.



## Options Database Key

- ***-malloc_dump <optional filename> -*** Dumps unfreed memory during call to `PetscFinalize()`





## Fortran Note
The calling sequence in Fortran is PetscMallocDump(integer ierr)
The fp defaults to stdout.


## Notes
Uses `MPI_COMM_WORLD` to display rank, because this may be called in `PetscFinalize()` after `PETSC_COMM_WORLD` has been freed.

When called in `PetscFinalize()` dumps only the allocations that have not been properly freed

`PetscMallocView()` prints a list of all memory ever allocated


## See Also
 `PetscMallocGetCurrentUsage()`, `PetscMallocView()`, `PetscMallocViewSet()`, `PetscMallocValidate()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/memory/mtr.c.html#PetscMallocDump">src/sys/memory/mtr.c</A>


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