使用delete来销毁原始/对象类型但不释放内存 [英] use delete to destroy primitive/object types but memory is not freed

查看:92
本文介绍了使用delete来销毁原始/对象类型但不释放内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


这是一个简单的问题,我想。

int main(){

double * g = new double;

* g = 9;

delete g;

cout<<的sizeof(克)<<" "<<的sizeof(双)<<" "<<的sizeof(* G)<<" "<< * G<<" "<< endl;

* g = 111;

cout<<的sizeof(克)<<" "<<的sizeof(双)<<" "<<的sizeof(* G)<<" "<< * G<<" "<< endl;

返回0;

}


输出:

4 8 8 9

4 8 8 111

虽然我删除了g,为什么我仍然可以使用它并且它引用

实际内存?

使用new和

删除创建和删除对象类型时也会发生同样的情况!


请不要回答您的想法,而是回答实际情况。如果

您可以指向我可以阅读的网络资源,那将是

太棒了!


谢谢提前。

问候,

jimjim

Hello,

This is a simple question for you all, I guess .
int main(){
double *g= new double;
*g = 9;
delete g;
cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl;
*g = 111;
cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl;
return 0;
}

The output:
4 8 8 9
4 8 8 111

Although I delete g, why is it that I can still use it and it references to
actual memory?

The same happens when creating and deleting object types with new and
delete!

Please dont answer with what you think but with what actually happens. If
you can point me to web sources I can read on this, it would have been
great!

Thank you in advance.
Regards,
jimjim

推荐答案

jimjim< Fr *** ******@blueyonder.co.uk>这样说:
jimjim <Fr*********@blueyonder.co.uk> spoke thus:
cout<<的sizeof(克)<<" "<<的sizeof(双)<<" "<<的sizeof(* G)<<" "<< * G<<" "<< endl;
cout<<的sizeof(克)<<" "<<的sizeof(双)<<" "<<的sizeof(* G)<<" "<< * G<<" "<< ENDL;
请不要回答您的想法,而是回答实际情况。如果你能指出我可以阅读的网络资源,它本来就很棒!
cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl;
cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl; Please dont answer with what you think but with what actually happens. If
you can point me to web sources I can read on this, it would have been
great!




(comp.lang.c ++就是这样----->)


你的帖子是comp.lang.c的主题。请访问

http:// www。 ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
http://benpfaff.org/writings/clc/off-topic.html


用于发布指南和常见问题。谢谢。


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。



(comp.lang.c++ is that way ----->)

Your post is off-topic for comp.lang.c. Please visit

http://www.ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
http://benpfaff.org/writings/clc/off-topic.html

for posting guidelines and frequently asked questions. Thank you.

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.


jimjim< Fr ********* @ blueyonder.co.uk>这样说:
jimjim <Fr*********@blueyonder.co.uk> spoke thus:
cout<<的sizeof(克)<<" "<<的sizeof(双)<<" "<<的sizeof(* G)<<" "<< * G<<" "<< endl;
cout<<的sizeof(克)<<" "<<的sizeof(双)<<" "<<的sizeof(* G)<<" "<< * G<<" "<< ENDL;
请不要回答您的想法,而是回答实际情况。如果你能指出我可以阅读的网络资源,它本来就很棒!
cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl;
cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl; Please dont answer with what you think but with what actually happens. If
you can point me to web sources I can read on this, it would have been
great!




(comp.lang.c ++就是这样----->)


你的帖子是comp.lang.c的主题。请访问

http:// www。 ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
http://benpfaff.org/writings/clc/off-topic.html


用于发布指南和常见问题。谢谢。


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。



(comp.lang.c++ is that way ----->)

Your post is off-topic for comp.lang.c. Please visit

http://www.ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
http://benpfaff.org/writings/clc/off-topic.html

for posting guidelines and frequently asked questions. Thank you.

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.


jimjim写道:

你好,

这对你来说是一个简单的问题所有,我想。
int main(){
double * g = new double;
[...]

Hello,

This is a simple question for you all, I guess .
int main(){
double *g= new double;
[...]




在那里停下来:这个问题只是因为我们的非简单

- 所有这些都在comp.lang.c中。对于他们来说也许这很简单

-在comp.lang.c ++中都是如此。当您穿过非军事区时,请仔细踩下



-
Er ********* @ sun.com


这篇关于使用delete来销毁原始/对象类型但不释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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