if you don't delete, your array will just be floating around ... lost in space ... or RAM and you will lose access to it FOREVER haha but If the code is small enough (ex a class project) its not gonna make a big difference. It is technically a memory leak though
All my fault, I should provide you the accurate scenario. Currently I am debugging a legacy c++ program which runs in linux OS. The program invokes a class static member function to get a db connection setting.
#include <iostream>
#include <string>
usingnamespace std;
class DbSetting {
public:
static string* getDbSettings();
};
string* DbSetting::getDbSettings() {
string* settings = new string[4];
settings[0] = "dbname";
settings[1] = "server";
settings[2] = "username";
settings[3] = "password";
return settings;
}
int main(int argc, char* argv[]) {
string* dbSettings = DbSetting::getDbSettings();
//dbSettings is used to construct a db connection string
return 0;
}
"dbSettings" is used to construct a db conneciton string but it never being "delete[] dbSettings" in "main" function. Such usage exists in some of other c++ legacy programs, I am not sure if I should report it as a bug of memory leak?