delete static object

来源:互联网 发布:python restful框架 编辑:程序博客网 时间:2024/05/17 07:49

If the data is static, it isn't allocated on the heap, and it will be destructed during the shutdown of the process.If it is a pointer to the data which is static, e.g.:

Something* MyClass::aPointer = new Something; 

Then like all other dynamically allocated data, it will only be destructed when you delete it. There are two frequent solutions:use a smart pointer, which has a destructor which deletes it, ordon't delete it; in most cases, there's really no reason to call the destructor, and if you happen to use the instance in the destructors of other static objects, you'll run into an order of destruction problem.