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.