我们是否应该释放为std :: locale分配的资源 [英] Should we release the allocated resource for std::locale

查看:104
本文介绍了我们是否应该释放为std :: locale分配的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

const std::locale fmt2(std::locale::classic(),
                       new boost::gregorian::date_input_facet("%m/%d/%Y"));

在第二个参数中,我们使用new boost::gregorian::date_input_facet("%m/%d/%Y").

In the second parameter, we use new boost::gregorian::date_input_facet("%m/%d/%Y").

问题:我是否需要考虑释放分配的资源?

Question: Do I need to concern to release the allocated resource?

谢谢

推荐答案

否.需要实现来释放内存本身(除非您另外指定):

No. The implementation is required to deallocate the memory itself (unless you specify otherwise):

22.3.1.1.2类locale::facet

对于refs == 0,当销毁包含构面的最后一个语言环境对象时,实现将执行delete static_cast<locale::facet*>(f)(其中f是指向构面的指针);否则,执行delete static_cast<locale::facet*>(f)(其中f是指向构面的指针).对于refs == 1,实现永远不会破坏构面.

For refs == 0, the implementation performs delete static_cast<locale::facet*>(f) (where f is a pointer to the facet) when the last locale object containing the facet is destroyed; for refs == 1, the implementation never destroys the facet.

这篇关于我们是否应该释放为std :: locale分配的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆