C ++ Array Memory leakage, or is it insecure?

Source: Internet
Author: User

Vector <double *> color_list;

Void F ()

{

Double Color [4] = {1.0, 0.0, 0.0, 1.0 };
Color_list.push_back (color );

}

Will Memory leakage be defined in this way?

I have defined a double color [4] = {1.0, 0.0, 0.0, 1.0 };
Then, the pointer of the array is saved.
Will the memory be automatically released?

James:
Your Pointer is a wild pointer.

If the function that you define the array ends, although the content in the space may not change, it is insecure to use this pointer.
This is wrong, though not always a problem... The global variables in your array should not cause any problems.
Me:
But if double * c = new double [4]; is this safe?
James 20:01:43
Are you sure you want to use the array and pointer in the same function ???
20:01:58 AM
No. None of them are in the same class.
James 20:02:03
You don't want to release him, okay?
20:02:16 AM
My program will be released at the end
20:02:27 AM
Or if I don't want it, release it myself.
James 20:02:31
Then you should keep the member variable and release it in the final destructor.
20:02:59 AM
That is, the self-defined array in C ++
Double C [4];
Memory is not safe if the function is over and then referenced?
James 20:04:06
This is obviously the case. As defined in the function, it is wrong to end the function and use it again.

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.