目录
前言
* 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。
http://indianpharmgrx.com/# Online medicine home delivery
http://mexicanpharmgrx.shop/# mexican pharmacy
https://mexicanpharmgrx.shop/# mexican pharmacy
top 10 pharmacies in india: Healthcare and medicines from India – indian pharmacy online
pharmacies in mexico that ship to usa: mexican pharmacy – п»їbest mexican online pharmacies
indian pharmacy: indian pharmacy delivery – indian pharmacy
http://mexicanpharmgrx.com/# buying prescription drugs in mexico online
indian pharmacy Generic Medicine India to USA buy prescription drugs from india
http://indianpharmgrx.shop/# reputable indian pharmacies
mexican drugstore online online pharmacy in Mexico mexican border pharmacies shipping to usa
http://mexicanpharmgrx.shop/# buying prescription drugs in mexico
mexico pharmacy: Mexico drugstore – mexican border pharmacies shipping to usa
cheapest online pharmacy india Generic Medicine India to USA buy prescription drugs from india
http://canadianpharmgrx.xyz/# pharmacy com canada
canada drugstore pharmacy rx: Pharmacies in Canada that ship to the US – canada pharmacy 24h
ordering drugs from canada: canadian pharmacy – canadian pharmacy online reviews
mexican mail order pharmacies mexican pharmacy buying prescription drugs in mexico online
https://mexicanpharmgrx.shop/# pharmacies in mexico that ship to usa
http://canadianpharmgrx.com/# my canadian pharmacy reviews
https://indianpharmgrx.shop/# reputable indian pharmacies
mexican online pharmacies prescription drugs mexican rx online pharmacies in mexico that ship to usa
https://indianpharmgrx.com/# legitimate online pharmacies india
mexico drug stores pharmacies: Mexico drugstore – buying prescription drugs in mexico online
buying from online mexican pharmacy: Mexico drugstore – mexican drugstore online
https://canadianpharmgrx.xyz/# canadian pharmacies online
Online medicine order: Generic Medicine India to USA – best online pharmacy india
pharmacy website india indian pharmacy buy prescription drugs from india
http://mexicanpharmgrx.com/# mexico pharmacies prescription drugs
best mail order pharmacy canada Cheapest drug prices Canada canadian pharmacy prices
Generic Cialis without a doctor prescription cialis without a doctor prescription cheapest cialis
Tadalafil Tablet: cheapest cialis – Buy Cialis online
https://tadalafiliq.shop/# Buy Cialis online
Kamagra tablets buy Kamagra Kamagra Oral Jelly
http://kamagraiq.shop/# Kamagra 100mg price
Generic Viagra for sale: cheapest viagra – Buy Viagra online cheap
cialis for sale: Cialis 20mg price in USA – buy cialis pill
http://tadalafiliq.com/# cheapest cialis
http://kamagraiq.com/# Kamagra tablets
buy kamagra online usa: Kamagra Oral Jelly Price – Kamagra 100mg price
super kamagra Kamagra Oral Jelly Price buy Kamagra
http://kamagraiq.com/# Kamagra 100mg price
super kamagra: Kamagra Iq – buy Kamagra
http://sildenafiliq.com/# buy Viagra over the counter
п»їkamagra Sildenafil Oral Jelly buy Kamagra
Kamagra 100mg price: buy kamagra online usa – buy kamagra online usa
http://kamagraiq.shop/# Kamagra tablets
Cheapest Sildenafil online: sildenafil iq – best price for viagra 100mg
http://sildenafiliq.com/# Order Viagra 50 mg online
cheapest cialis cheapest cialis Generic Cialis without a doctor prescription
Cheapest Sildenafil online: buy viagra online – viagra canada