Yes, if the array has a fixed size and is not allocated dynamically, then the memory will be released in the MyObject destructor. You may find that using std::array is a more convenient way to store a fixed-size array:
#include <array> struct MyObject { std::array<float, 10> array; };
In addition, if you are going to dynamically allocate memory for MyObject , I recommend using a smart pointer, such as unique_ptr :
#include <memory> auto my_object = std::unique_ptr<MyObject>(new MyObject); //auto my_object = std::make_unique<MyObject>(); // C++14
If you need a dynamically distributed array with a variable size, I recommend using vector :
#include <vector> struct MyObject { std::vector<float> array; };
In this case, the memory allocated for the array will be freed when the MyObject destructor is called.
source share