I'm storing an object (TTF_Font) in a shared_ptr that is provided to me from a third-party API. I cannot use new or delete on the object, so the shared_ptr is also provided a "freeing" functor.
// Functor
struct CloseFont
{
void operator()(TTF_Font* font) const
{
if(font != NULL) {
TTF_CloseFont(font);
}
}
};
boost::shared_ptr<TTF_Font> screenFont;
screenFont = boost::shared_ptr<TTF_Font>( TTF_OpenFont("slkscr.ttf", 8), CloseFont() );
If, later, I need to explicitly free this object is it correct to do this:
screenFont.reset();
And then let the screenFont object (the actual shared_ptr object) be destroyed natually?