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

/ 2,077评论 / 7260阅读 / 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. WilliamRen说道:

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

  2. RandallGuesE说道:

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

  3. RandallGuesE说道:

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

  4. Davidfrify说道:

    ciprofloxacin cipro buy cipro online without prescription

  5. Davidfrify说道:

    Abortion pills online Abortion pills online buy cytotec online

  6. WilliamRen说道:

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

  7. RonaldSwobe说道:

    http://ciprofloxacin.tech/# buy ciprofloxacin

  8. RandallGuesE说道:

    purchase cipro: ciprofloxacin mail online – ciprofloxacin over the counter

  9. RonaldSwobe说道:

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

  10. RandallGuesE说道:

    tamoxifen lawsuit: tamoxifen and bone density – tamoxifen 20 mg

  11. WilliamRen说道:

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

  12. Davidfrify说道:

    buy tamoxifen nolvadex only pct nolvadex generic

  13. Davidfrify说道:

    buying propecia propecia order buying generic propecia online

  14. WilliamRen说道:

    https://nolvadex.life/# tamoxifen moa

  15. Davidfrify说道:

    purchase cipro buy cipro online without prescription buy ciprofloxacin

  16. Davidfrify说道:

    does tamoxifen cause menopause nolvadex steroids tamoxifen rash pictures

  17. RandallGuesE说道:

    nolvadex 20mg: nolvadex price – tamoxifen hip pain

  18. WilliamRen说道:

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

  19. RandallGuesE说道:

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

  20. WilliamRen说道:

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

  21. Davidfrify说道:

    lisinopril 2.5 lisinopril cheap price lisinopril generic over the counter

  22. Davidfrify说道:

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

  23. RandallGuesE说道:

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

  24. WilliamRen说道:

    http://ciprofloxacin.tech/# antibiotics cipro

  25. RandallGuesE说道:

    tamoxifenworld: nolvadex 10mg – effexor and tamoxifen

发表回复

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