delete void pointer是否会有内存泄漏?

看下面一个简单例子

class Test{
public:
Test(){
printf ("constructor\n");
}
~Test(){
printf("destructor");
}
}; int main(int argc, char *argv[])
{
Test *p = new Test();
void *p1 = p;
delete p1;
printf("the end\n");
getchar(); return 0;
}

  结果输出:

从输出可以看出来,没有调用类的析构函数;

网上解释:

It depends on "safe." It will usually work because information is stored along with the pointer about the allocation itself, so the deallocator can return it to the right place. In this sense it is "safe" as long as your allocator uses internal boundary tags. (Many do.)

However, as mentioned above, deleting a void pointer will not call destructors, which can be a problem. In that sense, it is not "safe."

参考:http://stackoverflow.com/questions/941832/is-it-safe-to-delete-a-void-pointer

delete void pointer的更多相关文章

  1. Pointer arithmetic for void pointer in C

    http://stackoverflow.com/questions/3523145/pointer-arithmetic-for-void-pointer-in-c When a pointer t ...

  2. 【ThinkingInC++】65、使用delete void*可能会出错

    /** * 书本:[ThinkingInC++] * 功能:使用delete void*可能会出错 * 时间:2014年10月5日14:31:43 * 作者:cutter_point */ #incl ...

  3. 微信SDK导入报错 Undefined symbols for architecture i386:"operator delete[](void*)", referenced from:

    异常信息: Undefined symbols for architecture i386:  "operator delete[](void*)", referenced fro ...

  4. differences between null pointer and void pointer.

    These are two different concepts, you cannot compare them. What the difference between the skunk and ...

  5. delete void *

    看代码的时候看到 typedef char xxx[sizeof(T) ? 1 : -1]; 这种语句 如:JavaScriptCore/wtf/OwnPtrCommon.h template < ...

  6. 不要轻易delete void*指针,这样会隐藏比较多的错误。

    #include<iostream> using namespace std; class Object{ void* data; const int size; const char i ...

  7. javascript特殊运算符(in,instanceof,typeof,delete,void,逗号)

    in运算符                 in运算符要求其左边的运算数是一个字符串,或可以被转换为字符串,右边的运算数十一个对象或数组.如果该 运算符左边的值是右边对象的一个属性名,则返回true, ...

  8. C++ 重载new和delete操作符

    原因: C++标准库提供的new和delete操作符,是一个通用实现,未针对具体对象做具体分析 存在分配器速度慢.小型对象空间浪费严重等问题,不适用于对效率和内存有限制的应用场景   好处: 灵活的内 ...

  9. 重载全局new/delete实现内存检测

    下面介绍用重载new/delete运算符的方式来实现一个简单的内存泄露检测工具,基本思想是重载全局new/delete运算符,被检测代码调用new和delete运算符时就会调用重载过的operator ...

随机推荐

  1. iOS-Socket编程体验

    CHENYILONG Blog Socket编程体验 Socket编程体验  技术博客http://www.cnblogs.com/ChenYilong/新浪微博http://weibo.com/lu ...

  2. [BZOJ 2257][JSOI2009]瓶子和燃料 题解(GCD)

    [BZOJ 2257][JSOI2009]瓶子和燃料 Description jyy就一直想着尽快回地球,可惜他飞船的燃料不够了. 有一天他又去向火星人要燃料,这次火星人答应了,要jyy用飞船上的瓶子 ...

  3. tf.range()函数

    range()函数用于创建数字序列变量,有以下两种形式: range(limit, delta=1, dtype=None, name='range') range(start, limit, del ...

  4. 第6月第4天 AVMutableComposition AVMutableVideoComposition

    1. AVMutableComposition is a mutable subclass of AVComposition you use when you want to create a new ...

  5. 【配置】Spring Struts配置信息

  6. Install Shield中调用devcon自动安装硬件驱动程序

    1.安装驱动程序命令devcon安装好WINDDK之后,devcon.exe在"C:\WINDDK\3790.1830\tools\devcon"目录下.>devcon up ...

  7. 公共语言运行库(CLR)开发系列课程(2):Pinvoke 进阶 学习笔记

    上一章地址 API版本 具有字符串参数的API通常有两种版本 GetWindowText GetWindowTextA GetWindowTextW 缺省情况下CLR会自动寻找合适的匹配 CharSe ...

  8. 利用CSS改变输入框的光标颜色

    转:http://www.cnblogs.com/gymmer/p/6810367.html 代码: <!DOCTYPE html> <html lang="en" ...

  9. Ibatis.Net <![CDATA[ ]]>标记学习(九)

    当Sql语句中包含特殊字符时,例如: <select id="SelectOnePerson" resultMap="PersonModel"> s ...

  10. Densenet-Tensorflow

    在寻找densnet网络的时候,我发现了一个结构清晰完整的网络代码,在此作备份. https://github.com/taki0112/Densenet-Tensorflow Densenet-Te ...