目录
前言
* new申请的内存,即使你没有执行delete,在程序结束后,也会释放掉的。
* 但这样做会有很多弊端,下文将列举部分情况。
弊端
不delete的话被释放时不会执行析构函数
- 测试 - 在vs2022中:
- 定义一个test类,并在main函数中声明t1,t2,t3三个对象:
#include<iostream>
using namespace std;
class test
{
string name;
public:
test(const string& in_name)
{
name = in_name;
cout << "<< " + name + " 出现了,指针:" << this << endl;
}
~test()
{
cout << "<< " + name + "执行了析构函数,指针:" << this << endl;
}
};
int main()
{
test t1("t1");
test* t2 = new test("t2");
test* t3 = new test("t3");
cout << endl << endl;
delete t2;
cout << endl << endl << "<< main - return" << endl << endl;
return 0;
}
- 可以看到在main函数中,t2,t3是new出来的,我们手动把 t2 delete。
- 运行结果:
- 可以看到,t2因为我们手动delete而在main结束前执行了析构函数
- t1则main结束后执行了析构函数。
- t3则是由系统回收,可见它并没有执行析构函数
- 因此,如果析构函数中有输出提示,缓冲内容等需要执行,则应该手动delete。当然,即便没有也倡导自己手动delete。
casino tr?c tuy?n uy tín: dánh bài tr?c tuy?n – web c? b?c online uy tín
danh bai tr?c tuy?n web c? b?c online uy tin danh bai tr?c tuy?n
https://casinvietnam.shop/# danh bai tr?c tuy?n
http://casinvietnam.shop/# game c? b?c online uy tin
casino tr?c tuy?n uy tín: dánh bài tr?c tuy?n – web c? b?c online uy tín
https://casinvietnam.shop/# casino online uy tin
casino tr?c tuy?n web c? b?c online uy tin casino tr?c tuy?n uy tin
dánh bài tr?c tuy?n: casino tr?c tuy?n – casino tr?c tuy?n vi?t nam
casino online uy tin game c? b?c online uy tin casino tr?c tuy?n vi?t nam
http://casinvietnam.com/# casino tr?c tuy?n
https://onlinepharmacyworld.shop/# canadian pharmacy coupon code
canadian pharmacy discount coupon: cheapest prescription pharmacy – us pharmacy no prescription
http://medicationnoprescription.pro/# canadian prescription
no prescription medicines no prescription medicines ordering prescription drugs from canada
best ed pills online: where to get ed pills – erection pills online
http://onlinepharmacyworld.shop/# canada pharmacy coupon
http://edpill.top/# best ed pills online
buy prescription drugs without a prescription: overseas online pharmacy-no prescription – prescription meds from canada
https://onlinepharmacyworld.shop/# legal online pharmacy coupon code
buy ed pills online ed medications cost ed med online
http://onlinepharmacyworld.shop/# canadian pharmacy no prescription needed
http://medicationnoprescription.pro/# buy drugs online without prescription
ed pills for sale: where to get ed pills – where to buy ed pills
online ed medications ed meds by mail buy ed meds online
https://medicationnoprescription.pro/# meds no prescription
no prescription drugs online: buy medication online no prescription – online pharmacy reviews no prescription
ed meds online: online ed prescription – what is the cheapest ed medication
http://edpill.top/# erectile dysfunction online
https://edpill.top/# ed drugs online
http://onlinepharmacyworld.shop/# prescription free canadian pharmacy
canadian pharmacy no prescription needed online pharmacy no prescription prescription drugs online
https://medicationnoprescription.pro/# how to buy prescriptions from canada safely
cheapest ed meds: erectile dysfunction drugs online – erectile dysfunction pills for sale
Wow, superb weblog format! How lengthy have you ever
been blogging for? you made running a blog glance easy. The whole look of your web site is fantastic, let alone the content!
You can see similar here sklep online
cheapest prescription pharmacy cheapest prescription pharmacy buying prescription drugs from canada
https://prednisonea.store/# prednisone 30 mg coupon
where to buy generic clomid without insurance: where can i get clomid – how to get clomid for sale
ivermectin 12 mg: where can i buy oral ivermectin – stromectol for humans
buy generic clomid: where to get generic clomid without dr prescription – can i buy clomid without rx
https://azithromycina.pro/# where to buy zithromax in canada
buy prednisone without a prescription over the counter prednisone pills average cost of generic prednisone
https://clomida.pro/# how can i get generic clomid without insurance
prednisone: prednisone 60 mg – prednisone 5 mg tablet without a prescription
ivermectin 12 mg: ivermectin 0.1 uk – ivermectin generic
http://prednisonea.store/# how can i get prednisone online without a prescription
buy generic clomid without dr prescription where to buy generic clomid without a prescription cost clomid tablets
prednisone 25mg from canada: prednisone brand name – can i buy prednisone online without prescription
prednisone 2.5 mg: prednisone rx coupon – prednisone 50 mg canada
https://clomida.pro/# can i buy cheap clomid online
buy prednisone without rx prednisone prescription drug prednisone 10mg tabs