Memory leakage and the stack?

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Tim (Tim_at_discussions.microsoft.com)
Date: 07/14/04


Date: Wed, 14 Jul 2004 05:58:02 -0700


   I'm using Visual C++ 6.0 and the debugger is reporting memory leaks. I go to the line it references and it is within one of my methods. The line it points to is:

rect = new CRect(0, 0, vidWidth,vidHeight);

At the very start of the method I have:
CRect rect;

I was thinking rect would be automatically deallocated on method exit. Do I have to deallocate the memory rect is pointing to? When I try either delete rect; or delete [] rect; at runtime I get a 'user breakpoint encountered' dialog box, but I set no breakpoints at the line where I delete the rect variable.

So should the memory rect points to be automatically deallocated upon method exit, and if not then why can't I delete it with the delete [] rect or delete rect statements?

Thanks!
[Tim]