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

/ 2,079评论 / 7271阅读 / 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. Bernardordib说道:

    casino tr?c tuy?n uy tín: dánh bài tr?c tuy?n – web c? b?c online uy tín

  2. MichaelFah说道:

    danh bai tr?c tuy?n web c? b?c online uy tin danh bai tr?c tuy?n

  3. JamesAnirm说道:

    https://casinvietnam.shop/# danh bai tr?c tuy?n

  4. Jesseelell说道:

    http://casinvietnam.shop/# game c? b?c online uy tin

  5. JoshuaPreri说道:

    casino tr?c tuy?n uy tín: dánh bài tr?c tuy?n – web c? b?c online uy tín

  6. Walteronerb说道:

    https://casinvietnam.shop/# casino online uy tin

  7. Chrisror说道:

    casino tr?c tuy?n web c? b?c online uy tin casino tr?c tuy?n uy tin

  8. JoshuaPreri说道:

    dánh bài tr?c tuy?n: casino tr?c tuy?n – casino tr?c tuy?n vi?t nam

  9. Chrisror说道:

    casino online uy tin game c? b?c online uy tin casino tr?c tuy?n vi?t nam

  10. Walteronerb说道:

    http://casinvietnam.com/# casino tr?c tuy?n

  11. Armandosed说道:

    https://onlinepharmacyworld.shop/# canadian pharmacy coupon code

  12. AustinWhoto说道:

    canadian pharmacy discount coupon: cheapest prescription pharmacy – us pharmacy no prescription

  13. HarveyBeemi说道:

    http://medicationnoprescription.pro/# canadian prescription

  14. PhilipBup说道:

    no prescription medicines no prescription medicines ordering prescription drugs from canada

  15. MatthewDoolo说道:

    best ed pills online: where to get ed pills – erection pills online

  16. HarveyBox说道:

    http://onlinepharmacyworld.shop/# canada pharmacy coupon

  17. Armandosed说道:

    http://edpill.top/# best ed pills online

  18. MatthewDoolo说道:

    buy prescription drugs without a prescription: overseas online pharmacy-no prescription – prescription meds from canada

  19. Armandosed说道:

    https://onlinepharmacyworld.shop/# legal online pharmacy coupon code

  20. PhilipBup说道:

    buy ed pills online ed medications cost ed med online

  21. HarveyBeemi说道:

    http://onlinepharmacyworld.shop/# canadian pharmacy no prescription needed

  22. Armandosed说道:

    http://medicationnoprescription.pro/# buy drugs online without prescription

  23. MatthewDoolo说道:

    ed pills for sale: where to get ed pills – where to buy ed pills

  24. PhilipBup说道:

    online ed medications ed meds by mail buy ed meds online

  25. AustinWhoto说道:

    no prescription drugs online: buy medication online no prescription – online pharmacy reviews no prescription

  26. MatthewDoolo说道:

    ed meds online: online ed prescription – what is the cheapest ed medication

  27. HarveyBox说道:

    http://edpill.top/# erectile dysfunction online

  28. Armandosed说道:

    https://edpill.top/# ed drugs online

  29. HarveyBeemi说道:

    http://onlinepharmacyworld.shop/# prescription free canadian pharmacy

  30. PhilipBup说道:

    canadian pharmacy no prescription needed online pharmacy no prescription prescription drugs online

  31. Armandosed说道:

    https://medicationnoprescription.pro/# how to buy prescriptions from canada safely

  32. MatthewDoolo说道:

    cheapest ed meds: erectile dysfunction drugs online – erectile dysfunction pills for sale

  33. 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

  34. PhilipBup说道:

    cheapest prescription pharmacy cheapest prescription pharmacy buying prescription drugs from canada

  35. BrainSaw说道:

    https://prednisonea.store/# prednisone 30 mg coupon

  36. DomenicDobby说道:

    where to buy generic clomid without insurance: where can i get clomid – how to get clomid for sale

  37. BryanSturf说道:

    ivermectin 12 mg: where can i buy oral ivermectin – stromectol for humans

  38. MichaelPycle说道:

    buy generic clomid: where to get generic clomid without dr prescription – can i buy clomid without rx

  39. Josephtrink说道:

    https://azithromycina.pro/# where to buy zithromax in canada

  40. JamesLot说道:

    buy prednisone without a prescription over the counter prednisone pills average cost of generic prednisone

  41. BrainSaw说道:

    https://clomida.pro/# how can i get generic clomid without insurance

  42. MichaelPycle说道:

    prednisone: prednisone 60 mg – prednisone 5 mg tablet without a prescription

  43. MichaelPycle说道:

    ivermectin 12 mg: ivermectin 0.1 uk – ivermectin generic

  44. BrainSaw说道:

    http://prednisonea.store/# how can i get prednisone online without a prescription

  45. JamesLot说道:

    buy generic clomid without dr prescription where to buy generic clomid without a prescription cost clomid tablets

  46. BryanSturf说道:

    prednisone 25mg from canada: prednisone brand name – can i buy prednisone online without prescription

  47. MichaelPycle说道:

    prednisone 2.5 mg: prednisone rx coupon – prednisone 50 mg canada

  48. BrainSaw说道:

    https://clomida.pro/# can i buy cheap clomid online

  49. JamesLot说道:

    buy prednisone without rx prednisone prescription drug prednisone 10mg tabs

回复 BryanSturf 取消回复

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