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

/ 7,300评论 / 21818阅读 / 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. JaimeNer说道:

    zithromax azithromycin zithromax online australia where can i purchase zithromax online

  2. RobertUnsuh说道:

    how to get zithromax over the counter: zithromax for sale usa – zithromax for sale usa

  3. ArmandoLiaig说道:

    ciprofloxacin generic: buy ciprofloxacin over the counter – where to buy cipro online

  4. This site was… how do you say it? Relevant!! Finally I’ve found something that helped me. Thanks a lot!

  5. ArmandoLiaig说道:

    buy cipro without rx: buy cipro online without prescription – where to buy cipro online

  6. RobertUnsuh说道:

    lisinopril 10 mg order online: zestoretic canada – lisinopril 2.5 mg

  7. JaimeNer说道:

    how can i get clomid for sale order cheap clomid now cost of clomid without insurance

  8. JimmieInawl说道:

    https://lisinoprilus.com/# zestril tab 10mg

  9. JimmieInawl说道:

    http://clomid.store/# how can i get clomid price

  10. JaimeNer说道:

    lisinopril 20 mg cost lisinopril 3760 buy lisinopril 2.5 mg

  11. mrs claus porn说道:

    It’s hard to find well-informed people on this topic, however, you sound like you know what you’re talking about! Thanks

  12. RobertUnsuh说道:

    buy generic zithromax online: zithromax over the counter – can you buy zithromax over the counter in canada

  13. JimmieInawl说道:

    https://cytotec.top/# buy cytotec pills online cheap

  14. ArmandoLiaig说道:

    zithromax azithromycin: zithromax drug – how to get zithromax online

  15. ArmandoLiaig说道:

    can i order generic clomid no prescription: cost of clomid without prescription – where to get generic clomid without prescription

  16. bookmarked!!, I really like your blog.

  17. JaimeNer说道:

    buy cheap clomid buy generic clomid without prescription can you get cheap clomid online

  18. RobertUnsuh说道:

    zestril 2.5 mg: order lisinopril 10 mg – generic zestoretic

  19. ArmandoLiaig说道:

    purchase zithromax z-pak: where can i get zithromax over the counter – buy cheap generic zithromax

  20. Тут можно преобрести сейф взломостойкий цена купить сейф взломостойкий

  21. JaimeNer说道:

    can you buy zithromax over the counter in mexico buy zithromax online cheap zithromax capsules price

  22. JimmieInawl说道:

    https://azithromycinus.com/# buy zithromax online australia

  23. JimmieInawl说道:

    https://cytotec.top/# buy cytotec in usa

  24. RobertUnsuh说道:

    where to buy zithromax in canada: zithromax coupon – purchase zithromax z-pak

  25. You have made some good points there. I looked on the web to find out more about the issue and found most individuals will go along with your views on this site.

  26. ArmandoLiaig说道:

    price of lisinopril 5mg: zestril tablet – zestoretic 20 25 mg

  27. JaimeNer说道:

    lisinopril 5 mg pill lisinopril 10 mg over the counter lisinopril 30 mg

  28. thickstella porn说道:

    I love it whenever people come together and share thoughts. Great site, continue the good work.

  29. RobertUnsuh说道:

    cost of generic zithromax: generic zithromax medicine – how to get zithromax online

  30. ArmandoLiaig说道:

    zithromax online pharmacy canada: order zithromax over the counter – zithromax 250 mg

  31. JimmieInawl说道:

    https://ciprofloxacin.cheap/# ciprofloxacin mail online

  32. JimmieInawl说道:

    http://azithromycinus.com/# zithromax generic cost

  33. JaimeNer说道:

    purchase cytotec Cytotec 200mcg price Abortion pills online

  34. RobertUnsuh说道:

    buying generic clomid without prescription: cost of clomid no prescription – how can i get cheap clomid for sale

  35. Greetings! Very useful advice within this article! It’s the little changes that make the greatest changes. Thanks for sharing!

  36. tubidy mp3说道:

    Right here is the right blog for anyone who really wants to find out about this topic. You realize so much its almost hard to argue with you (not that I actually would want to…HaHa). You definitely put a new spin on a subject which has been discussed for ages. Wonderful stuff, just great.

  37. taktichn__vapn说道:

    Тактичные штаны: идеальный выбор для стильных мужчин, как носить их с другой одеждой.
    Неотъемлемая часть гардероба – тактичные штаны, которые подчеркнут ваш стиль и индивидуальность.
    Как найти идеальные тактичные штаны, который подчеркнет вашу уверенность и статус.
    Лучшие модели тактичных штанов для мужчин, которые подчеркнут вашу спортивную натуру.
    Советы по выбору тактичных штанов для мужчин, чтобы подчеркнуть свою уникальность и индивидуальность.
    Тактичные штаны: вечная классика мужского гардероба, которые подчеркнут ваш вкус и качество вашей одежды.
    Тактичные штаны: универсальный выбор для различных ситуаций, которые подчеркнут ваш профессионализм и серьезность.
    купить тактичні штани зсу https://dffrgrgrgdhajshf.com.ua/ .

  38. JaimeNer说道:

    where to get zithromax over the counter buy zithromax no prescription zithromax online

  39. Arrivia is a Scottsdale, Arizona-based travel expertise and loyalty resolution with ten workplaces around the globe, together with within the United States, India, Mexico, the United Kingdom, Australia, Portugal, and the Philippines.

  40. RobertUnsuh说道:

    zestoretic 20 12.5: lisinopril 5 mg tablet – lisinopril 2

  41. Собственное производство металлоконструкций. Если вас интересует навесы под ключ мы предлогаем изготовление под ключ навесы из металлочерепицы

  42. JimmieInawl说道:

    https://ciprofloxacin.cheap/# buy ciprofloxacin over the counter

  43. JimmieInawl说道:

    http://cytotec.top/# cytotec buy online usa

  44. It’s difficult to find experienced people on this subject, but you seem like you know what you’re talking about! Thanks

  45. JaimeNer说道:

    lisinopril tabs prinivil medication lisinopril cheap price

发表回复

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