I'm very cautious about memory leaks, so I thought I'd have this verified. In the following example would there be a memory leak? My gut instinct says yes.
class Handler // Class definition
{public:
~Handler();
int* ptrToInts;
};
Handler::~Handler() // Class destructor
{
delete[] ptrToInts;
}
Handler handler; // Global object
void aFunction()
{
handler.ptrToInts = new int[20];
}
int main()
{
bool quit = false;
while(!quit)
{
aFunction();
}
return 0;
}
Would ptrToInts be creating 20 separate new ints in separate memory on the heapeach time?
Also, another question is if it weren't for the destructor, would the dynamically allocated memory be freed? Seeing as though the lifetime of the class is the duration of the program, would it do cleanup of all the "new" memory?
Edit: Thanks for the answers. The reason I'm asking this is because I'm trying to get around calling new and delete every time WndProc is called for Raw Input basically, which is how the MSDN tells you to do it. Seems very inefficient.