stbenge <stb### [at] hotmailcom> wrote:
> I don't find it too difficult to delete every "new".
You would be surprised.
There's a potential memory leak here:
void foo()
{
char* s = new char[100];
bar();
delete[] s;
}
There's a potential memory leak here:
class A
{
char* s;
public:
A(): s(new char[100]) {}
~A() { delete[] s; }
};
Naturally both of these leaks can be fixed by using cleaner code:
void foo()
{
std::string s(100, ' ');
bar();
}
class A
{
std::string s;
public:
A(): s(100, ' ') {}
};
No 'new' -> no leaks.
--
- Warp
Post a reply to this message
|