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

/ 2,431评论 / 8077阅读 / 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. IsaacPem说道:

    Generic Tadalafil 20mg price: Buy Tadalafil 20mg – cialis generic

  2. RobertEsses说道:

    https://tadalafiliq.shop/# cheapest cialis

  3. IsaacPem说道:

    Kamagra 100mg: Kamagra gel – buy kamagra online usa

  4. Johnniecew说道:

    http://tadalafiliq.shop/# Generic Tadalafil 20mg price

  5. Danielleant说道:

    Kamagra 100mg price Sildenafil Oral Jelly buy Kamagra

  6. RobertEsses说道:

    http://sildenafiliq.xyz/# best price for viagra 100mg

  7. IsaacPem说道:

    Buy Tadalafil 10mg: cialis without a doctor prescription – Buy Tadalafil 20mg

  8. Danielleant说道:

    Viagra tablet online generic ed pills Cheap Viagra 100mg

  9. Good day! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get my site to rank for some targeted keywords but
    I’m not seeing very good gains. If you know of any please share.
    Thanks! I saw similar art here: List of Backlinks

  10. Johnniecew说道:

    http://tadalafiliq.com/# Buy Cialis online

  11. IsaacPem说道:

    Buy Tadalafil 5mg: Cialis without a doctor prescription – cialis for sale

  12. Chesterbloks说道:

    Generic Tadalafil 20mg price: cialis without a doctor prescription – Buy Cialis online

  13. Danielleant说道:

    buy viagra here cheapest viagra Cheap Viagra 100mg

  14. IsaacPem说道:

    Generic Cialis without a doctor prescription: Buy Cialis online – Buy Tadalafil 5mg

  15. Johnniecew说道:

    http://tadalafiliq.com/# Tadalafil price

  16. IsaacPem说道:

    cheapest cialis: tadalafil iq – Tadalafil Tablet

  17. Danielleant说道:

    buy Viagra online sildenafil iq viagra without prescription

  18. IsaacPem说道:

    sildenafil over the counter: buy viagra online – over the counter sildenafil

  19. Ralphnus说道:

    https://kamagraiq.com/# Kamagra Oral Jelly

  20. Danielleant说道:

    buy Kamagra Kamagra 100mg price Kamagra 100mg price

  21. Johnniecew说道:

    https://sildenafiliq.xyz/# Viagra generic over the counter

  22. IsaacPem说道:

    Kamagra 100mg price: Kamagra Iq – kamagra

  23. Chesterbloks说道:

    cheapest viagra: cheapest viagra – cheap viagra

  24. IsaacPem说道:

    Viagra Tablet price: Viagra online price – Buy Viagra online cheap

  25. Danielleant说道:

    Kamagra Oral Jelly Kamagra Oral Jelly Price Kamagra 100mg price

  26. RobertFup说道:

    http://clomidall.com/# can you get clomid without insurance

  27. Davidboano说道:

    cost of clomid pills where to buy cheap clomid prices cheap clomid

  28. Jamesscurl说道:

    http://zithromaxall.com/# zithromax cost australia

  29. RobertFup说道:

    http://prednisoneall.shop/# prednisone 5 mg tablet cost

  30. Davidboano说道:

    generic amoxicillin cost order amoxicillin online can we buy amoxcillin 500mg on ebay without prescription

  31. Edwardsmors说道:

    zithromax 500 price: zithromax online usa – can i buy zithromax over the counter

  32. RobertFup说道:

    http://prednisoneall.com/# buy prednisone online canada

  33. Jamesscurl说道:

    https://zithromaxall.com/# how to get zithromax over the counter

  34. DavidEvedo说道:

    prednisone 10 mg over the counter: can i buy prednisone from canada without a script – prednisone 20 mg in india

  35. RobertFup说道:

    https://prednisoneall.shop/# can i buy prednisone over the counter in usa

  36. Davidboano说道:

    amoxicillin over counter amoxicillin 30 capsules price cheap amoxicillin 500mg

  37. RobertFup说道:

    https://prednisoneall.com/# prednisone for sale no prescription

  38. Davidboano说道:

    amoxicillin 200 mg tablet amoxicillin 200 mg tablet amoxicillin discount coupon

  39. RobertFup说道:

    http://clomidall.com/# can i get generic clomid

  40. Jamesscurl说道:

    http://zithromaxall.shop/# zithromax online

  41. RobertFup说道:

    https://zithromaxall.com/# zithromax canadian pharmacy

  42. Davidboano说道:

    prednisone tablets canada purchase prednisone where can i get prednisone over the counter

  43. Edwardsmors说道:

    buying amoxicillin online: amoxicillin 500 capsule – order amoxicillin 500mg

  44. RobertFup说道:

    https://amoxilall.com/# amoxicillin no prescription

  45. Scrapebox List说道:

    Howdy! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get
    my website to rank for some targeted keywords but I’m not seeing very good gains.
    If you know of any please share. Appreciate it! I saw similar art
    here: Scrapebox List

  46. DavidEvedo说道:

    buying generic clomid: can i purchase clomid no prescription – can i purchase generic clomid

  47. Jamesscurl说道:

    http://prednisoneall.shop/# buy prednisone 40 mg

  48. Davidboano说道:

    can you get clomid online can i purchase generic clomid tablets buy clomid no prescription

  49. RobertFup说道:

    https://amoxilall.shop/# how to get amoxicillin over the counter

发表回复

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