# Isolating HDF5 resource leak - best practices

**URL:** <https://forum.hdfgroup.org/t/isolating-hdf5-resource-leak-best-practices/3068>\
**Category:** Hdf-forum archives\
**Created:** [November 25, 2013, 5:59am UTC](https://forum.hdfgroup.org/t/isolating-hdf5-resource-leak-best-practices/3068 "2013-11-25T05:59:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yue.nicholas](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/yue.nicholas/32/1529_2.png) [@yue.nicholas](https://forum.hdfgroup.org/u/yue.nicholas)\
**Post date:** [November 25, 2013, 5:59am UTC](https://forum.hdfgroup.org/t/isolating-hdf5-resource-leak-best-practices/3068/1 "2013-11-25T05:59:42Z")

</div>

Hi,

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I have a class which opens HDF file in the constructor and close HDF file in the destructor.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;All seems fine until I tried wrapping it up in a boost smart pointer in an OpenGL Glut application.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The H5fclose() fails (was fine without the smart pointer) so I am in the process of tracking down any HDF5 resource leak due to my bad programming.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Is there some mode we can build our application to use HDF5 libraries so that resources are track and some statistics can be printed/dump out for developers to isolate where resources were created but not freed ?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I can use valgrind but I thought it there is something more specific to HDF5, I can cut down on the noise and focus only on HDF5 resources to start with.

Cheers

> **···**
>
> --  
> Nicholas Yue  
> Graphics - RenderMan, Visualization, OpenGL, HDF5  
> Custom Dev - C++ porting, OSX, Linux, Windows  
> [http://au.linkedin.com/in/nicholasyue](http://au.linkedin.com/in/nicholasyue)
> 
> > **[NaiadTools](https://vimeo.com/channels/naiadtools)**
> >
> > NaiadTools related videos, including demonstration and training.

---

<div class="post-metadata">

**Author:** ![nevion](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/n/7993a0/32.png) [@nevion](https://forum.hdfgroup.org/u/nevion)\
**Post date:** [November 25, 2013, 6:17am UTC](https://forum.hdfgroup.org/t/isolating-hdf5-resource-leak-best-practices/3068/2 "2013-11-25T06:17:56Z")

</div>

I'd try to use the C++ api to simplify object management and reduce  
occurrence of such issues. You might need the attached patch to work with  
it though (git based pag, applies against 1.8.12).

[0006-bugfix-in-c-api-prevent-passing-H5F\_ACC\_CREATE-to-H5.patch](https://hdf-discourse-1.s3.amazonaws.com/original/1X/3e94489d0eea07453ab02cca5ba90101899b3a0f.patch) (987 Bytes)

> **···**
>
> On Sun, Nov 24, 2013 at 9:59 PM, Nicholas Yue \<yue.nicholas@gmail.com\>wrote:
> 
> > Hi,
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;I have a class which opens HDF file in the constructor and close HDF  
> > file in the destructor.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;All seems fine until I tried wrapping it up in a boost smart pointer  
> > in an OpenGL Glut application.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;The H5fclose() fails (was fine without the smart pointer) so I am in  
> > the process of tracking down any HDF5 resource leak due to my bad  
> > programming.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;Is there some mode we can build our application to use HDF5 libraries  
> > so that resources are track and some statistics can be printed/dump out for  
> > developers to isolate where resources were created but not freed ?
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;I can use valgrind but I thought it there is something more specific  
> > to HDF5, I can cut down on the noise and focus only on HDF5 resources to  
> > start with.
> > 
> > Cheers
> > 
> > --  
> > Nicholas Yue  
> > Graphics - RenderMan, Visualization, OpenGL, HDF5  
> > Custom Dev - C++ porting, OSX, Linux, Windows  
> > [Tan Meng (Nicholas) Yue - WildBrain | LinkedIn](http://au.linkedin.com/in/nicholasyue)  
> > [NaiadTools on Vimeo](https://vimeo.com/channels/naiadtools)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org  
> > [http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-](http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-)  
> > forum\_lists.hdfgroup.org
