Inadvertently memory leaks: Try-catch (CException *e)

Source: Internet
Author: User

As far as possible to ensure the robustness of the code under the premise

One more layer of try-catch can actually handle some surprises.

But all CException-based exceptions cannot be directly delete

The following is the wrong way of writing

Try
{
	
}
catch (CException *e)
{
	delete e;
}
Originally thought that the exception object is not manually released (that is, do not delete)

But today found running n Days of server program memory usage increases

When debugging, we also find that the VS gives a memory leak hint

To know that CException has its own Delete method and needs to be manually invoked

Just like that.

Try
{
	
}
catch (CException *e)
{
	e->delete ();
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.