[c++]new之后不delete的弊端

/ 6,144评论 / 19533阅读 / 0点赞

前言

* new申请的内存,即使你没有执行delete,在程序结束后,也会释放掉的。

* 但这样做会有很多弊端,下文将列举部分情况。


弊端

不delete的话被释放时不会执行析构函数

#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;
}

可能导致运行时占用大量内存,影响程序长时间运行

  1. RoscoeHailA说道:

    http://indianpharmgrx.com/# Online medicine home delivery

  2. RoscoeHailA说道:

    http://mexicanpharmgrx.shop/# mexican pharmacy

  3. RoscoeHailA说道:

    https://mexicanpharmgrx.shop/# mexican pharmacy

  4. DavidMus说道:

    top 10 pharmacies in india: Healthcare and medicines from India – indian pharmacy online

  5. Chasetit说道:

    pharmacies in mexico that ship to usa: mexican pharmacy – п»їbest mexican online pharmacies

  6. LamarViz说道:

    indian pharmacy: indian pharmacy delivery – indian pharmacy

  7. RoscoeHailA说道:

    http://mexicanpharmgrx.com/# buying prescription drugs in mexico online

  8. LarryAntic说道:

    indian pharmacy Generic Medicine India to USA buy prescription drugs from india

  9. RoscoeHailA说道:

    http://indianpharmgrx.shop/# reputable indian pharmacies

  10. LarryAntic说道:

    mexican drugstore online online pharmacy in Mexico mexican border pharmacies shipping to usa

  11. RoscoeHailA说道:

    http://mexicanpharmgrx.shop/# buying prescription drugs in mexico

  12. Chasetit说道:

    mexico pharmacy: Mexico drugstore – mexican border pharmacies shipping to usa

  13. LarryAntic说道:

    cheapest online pharmacy india Generic Medicine India to USA buy prescription drugs from india

  14. RoscoeHailA说道:

    http://canadianpharmgrx.xyz/# pharmacy com canada

  15. DavidMus说道:

    canada drugstore pharmacy rx: Pharmacies in Canada that ship to the US – canada pharmacy 24h

  16. LamarViz说道:

    ordering drugs from canada: canadian pharmacy – canadian pharmacy online reviews

  17. LarryAntic说道:

    mexican mail order pharmacies mexican pharmacy buying prescription drugs in mexico online

  18. RoscoeHailA说道:

    https://mexicanpharmgrx.shop/# pharmacies in mexico that ship to usa

  19. RoscoeHailA说道:

    http://canadianpharmgrx.com/# my canadian pharmacy reviews

  20. RoscoeHailA说道:

    https://indianpharmgrx.shop/# reputable indian pharmacies

  21. LarryAntic说道:

    mexican online pharmacies prescription drugs mexican rx online pharmacies in mexico that ship to usa

  22. RoscoeHailA说道:

    https://indianpharmgrx.com/# legitimate online pharmacies india

  23. Chasetit说道:

    mexico drug stores pharmacies: Mexico drugstore – buying prescription drugs in mexico online

  24. DavidMus说道:

    buying from online mexican pharmacy: Mexico drugstore – mexican drugstore online

  25. RoscoeHailA说道:

    https://canadianpharmgrx.xyz/# canadian pharmacies online

  26. LamarViz说道:

    Online medicine order: Generic Medicine India to USA – best online pharmacy india

  27. LarryAntic说道:

    pharmacy website india indian pharmacy buy prescription drugs from india

  28. RoscoeHailA说道:

    http://mexicanpharmgrx.com/# mexico pharmacies prescription drugs

  29. LarryAntic说道:

    best mail order pharmacy canada Cheapest drug prices Canada canadian pharmacy prices

  30. Danielleant说道:

    Generic Cialis without a doctor prescription cialis without a doctor prescription cheapest cialis

  31. IsaacPem说道:

    Tadalafil Tablet: cheapest cialis – Buy Cialis online

  32. RobertEsses说道:

    https://tadalafiliq.shop/# Buy Cialis online

  33. Danielleant说道:

    Kamagra tablets buy Kamagra Kamagra Oral Jelly

  34. Ralphnus说道:

    http://kamagraiq.shop/# Kamagra 100mg price

  35. IsaacPem说道:

    Generic Viagra for sale: cheapest viagra – Buy Viagra online cheap

  36. Chesterbloks说道:

    cialis for sale: Cialis 20mg price in USA – buy cialis pill

  37. Johnniecew说道:

    http://tadalafiliq.com/# cheapest cialis

  38. RobertEsses说道:

    http://kamagraiq.com/# Kamagra tablets

  39. IsaacPem说道:

    buy kamagra online usa: Kamagra Oral Jelly Price – Kamagra 100mg price

  40. Danielleant说道:

    super kamagra Kamagra Oral Jelly Price buy Kamagra

  41. RobertEsses说道:

    http://kamagraiq.com/# Kamagra 100mg price

  42. IsaacPem说道:

    super kamagra: Kamagra Iq – buy Kamagra

  43. Johnniecew说道:

    http://sildenafiliq.com/# buy Viagra over the counter

  44. Danielleant说道:

    п»їkamagra Sildenafil Oral Jelly buy Kamagra

  45. IsaacPem说道:

    Kamagra 100mg price: buy kamagra online usa – buy kamagra online usa

  46. RobertEsses说道:

    http://kamagraiq.shop/# Kamagra tablets

  47. IsaacPem说道:

    Cheapest Sildenafil online: sildenafil iq – best price for viagra 100mg

  48. Ralphnus说道:

    http://sildenafiliq.com/# Order Viagra 50 mg online

  49. Danielleant说道:

    cheapest cialis cheapest cialis Generic Cialis without a doctor prescription

  50. Chesterbloks说道:

    Cheapest Sildenafil online: buy viagra online – viagra canada

回复 IsaacPem 取消回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注