目录
前言
* 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。
https://viagras.online/# Cheapest Sildenafil online
http://levitrav.store/# Buy generic Levitra online
order cenforce Cenforce 150 mg online Purchase Cenforce Online
Buy Tadalafil 20mg Generic Tadalafil 20mg price Generic Cialis without a doctor prescription
http://kamagra.win/# buy Kamagra
http://viagras.online/# Sildenafil 100mg price
Cialis without a doctor prescription: buy cialis online – Cialis 20mg price
best price for viagra 100mg viagras.online sildenafil online
viagra canada viagras.online sildenafil 50 mg price
https://levitrav.store/# п»їLevitra price
https://levitrav.store/# Levitra 20 mg for sale
http://cialist.pro/# cheapest cialis
Buy Levitra 20mg online: Buy Vardenafil 20mg – Vardenafil online prescription
Buy Viagra online cheap: cheap viagra – Sildenafil 100mg price
buy kamagra online usa: kamagra – buy Kamagra
Buy Vardenafil 20mg Levitra 20 mg for sale Levitra generic best price
cenforce.pro Cenforce 100mg tablets for sale Buy Cenforce 100mg Online
https://levitrav.store/# Vardenafil online prescription
cheap propecia online: get propecia online – generic propecia price
tamoxifen generic: tamoxifen lawsuit – nolvadex d
https://finasteride.store/# cost of generic propecia tablets
cipro 500mg best prices ciprofloxacin over the counter cipro 500mg best prices
tamoxifen endometrium tamoxifen dose effexor and tamoxifen
https://finasteride.store/# propecia without dr prescription
ciprofloxacin 500mg buy online: cipro online no prescription in the usa – cipro pharmacy
lisinopril 40 mg india: lisinopril 60 mg tablet – lisinopril 25 mg cost
http://lisinopril.network/# lisinopril 5
ciprofloxacin cipro buy cipro online without prescription
Abortion pills online Abortion pills online buy cytotec online
https://ciprofloxacin.tech/# buy cipro online canada
http://ciprofloxacin.tech/# buy ciprofloxacin
purchase cipro: ciprofloxacin mail online – ciprofloxacin over the counter
http://lisinopril.network/# lisinopril 20 mg tablet price
tamoxifen lawsuit: tamoxifen and bone density – tamoxifen 20 mg
https://lisinopril.network/# lisinopril 12.5 mg
buy tamoxifen nolvadex only pct nolvadex generic
buying propecia propecia order buying generic propecia online
https://nolvadex.life/# tamoxifen moa
purchase cipro buy cipro online without prescription buy ciprofloxacin
does tamoxifen cause menopause nolvadex steroids tamoxifen rash pictures
nolvadex 20mg: nolvadex price – tamoxifen hip pain
https://cytotec.club/# buy cytotec online fast delivery
zestril canada: lisinopril 40 mg canada – lisinopril buy in canada
https://finasteride.store/# cost of cheap propecia pill
lisinopril 2.5 lisinopril cheap price lisinopril generic over the counter
Misoprostol 200 mg buy online buy cytotec buy cytotec online fast delivery
cost of cheap propecia without dr prescription: buy propecia online – propecia without insurance
https://ciprofloxacin.tech/# buy cipro
http://ciprofloxacin.tech/# antibiotics cipro
tamoxifenworld: nolvadex 10mg – effexor and tamoxifen