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

/ 6,141评论 / 19512阅读 / 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. DavidBiolo说道:

    https://viagras.online/# Cheapest Sildenafil online

  2. Charlesvox说道:

    http://levitrav.store/# Buy generic Levitra online

  3. Elmersoalf说道:

    order cenforce Cenforce 150 mg online Purchase Cenforce Online

  4. Elmersoalf说道:

    Buy Tadalafil 20mg Generic Tadalafil 20mg price Generic Cialis without a doctor prescription

  5. Charlesvox说道:

    http://kamagra.win/# buy Kamagra

  6. Tylerreunk说道:

    http://viagras.online/# Sildenafil 100mg price

  7. Georgefrege说道:

    Cialis without a doctor prescription: buy cialis online – Cialis 20mg price

  8. Elmersoalf说道:

    best price for viagra 100mg viagras.online sildenafil online

  9. Elmersoalf说道:

    viagra canada viagras.online sildenafil 50 mg price

  10. Charlesvox说道:

    https://levitrav.store/# п»їLevitra price

  11. Tylerreunk说道:

    https://levitrav.store/# Levitra 20 mg for sale

  12. Charlesvox说道:

    http://cialist.pro/# cheapest cialis

  13. Georgefrege说道:

    Buy Levitra 20mg online: Buy Vardenafil 20mg – Vardenafil online prescription

  14. Jamesexite说道:

    Buy Viagra online cheap: cheap viagra – Sildenafil 100mg price

  15. Jamesexite说道:

    buy kamagra online usa: kamagra – buy Kamagra

  16. Elmersoalf说道:

    Buy Vardenafil 20mg Levitra 20 mg for sale Levitra generic best price

  17. Elmersoalf说道:

    cenforce.pro Cenforce 100mg tablets for sale Buy Cenforce 100mg Online

  18. Charlesvox说道:

    https://levitrav.store/# Vardenafil online prescription

  19. RandallGuesE说道:

    cheap propecia online: get propecia online – generic propecia price

  20. RandallGuesE说道:

    tamoxifen generic: tamoxifen lawsuit – nolvadex d

  21. WilliamRen说道:

    https://finasteride.store/# cost of generic propecia tablets

  22. Davidfrify说道:

    cipro 500mg best prices ciprofloxacin over the counter cipro 500mg best prices

  23. Davidfrify说道:

    tamoxifen endometrium tamoxifen dose effexor and tamoxifen

  24. WilliamRen说道:

    https://finasteride.store/# propecia without dr prescription

  25. RandallGuesE说道:

    ciprofloxacin 500mg buy online: cipro online no prescription in the usa – cipro pharmacy

  26. RandallGuesE说道:

    lisinopril 40 mg india: lisinopril 60 mg tablet – lisinopril 25 mg cost

  27. Davidfrify说道:

    ciprofloxacin cipro buy cipro online without prescription

  28. Davidfrify说道:

    Abortion pills online Abortion pills online buy cytotec online

  29. WilliamRen说道:

    https://ciprofloxacin.tech/# buy cipro online canada

  30. RonaldSwobe说道:

    http://ciprofloxacin.tech/# buy ciprofloxacin

  31. RandallGuesE说道:

    purchase cipro: ciprofloxacin mail online – ciprofloxacin over the counter

  32. RonaldSwobe说道:

    http://lisinopril.network/# lisinopril 20 mg tablet price

  33. RandallGuesE说道:

    tamoxifen lawsuit: tamoxifen and bone density – tamoxifen 20 mg

  34. WilliamRen说道:

    https://lisinopril.network/# lisinopril 12.5 mg

  35. Davidfrify说道:

    buy tamoxifen nolvadex only pct nolvadex generic

  36. Davidfrify说道:

    buying propecia propecia order buying generic propecia online

  37. WilliamRen说道:

    https://nolvadex.life/# tamoxifen moa

  38. Davidfrify说道:

    purchase cipro buy cipro online without prescription buy ciprofloxacin

  39. Davidfrify说道:

    does tamoxifen cause menopause nolvadex steroids tamoxifen rash pictures

  40. RandallGuesE说道:

    nolvadex 20mg: nolvadex price – tamoxifen hip pain

  41. WilliamRen说道:

    https://cytotec.club/# buy cytotec online fast delivery

  42. RandallGuesE说道:

    zestril canada: lisinopril 40 mg canada – lisinopril buy in canada

  43. WilliamRen说道:

    https://finasteride.store/# cost of cheap propecia pill

  44. Davidfrify说道:

    lisinopril 2.5 lisinopril cheap price lisinopril generic over the counter

  45. Davidfrify说道:

    Misoprostol 200 mg buy online buy cytotec buy cytotec online fast delivery

  46. RandallGuesE说道:

    cost of cheap propecia without dr prescription: buy propecia online – propecia without insurance

  47. WilliamRen说道:

    http://ciprofloxacin.tech/# antibiotics cipro

  48. RandallGuesE说道:

    tamoxifenworld: nolvadex 10mg – effexor and tamoxifen

回复 Jamesexite 取消回复

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