Re: memory leak?
- From: "Doug Harrison [MVP]" <dsh@xxxxxxxx>
- Date: Sat, 28 Jul 2007 10:30:15 -0500
On Sat, 28 Jul 2007 11:02:40 -0000, wanwan <ericwan78@xxxxxxxxx> wrote:
I found a solution that doesn't make too much sense to me.
Originally I used malloc and free in treating the use of memory in the
char pointer like so:
char* ca = (char*) malloc(1234*sizeof(char));
Multiplying by sizeof(char) is pointless, because sizeof(char) == 1 by
definition.
...
free(ca);
.... It caused memory leak.
After playing with my code, I change to using new and delete. The
memory leak is now gone.
I thought they are the same thing. .Anyway, hope someone else can make
use of my findings.
They should be the same thing WRT leak detection (verify by temporarily
deleting the delete), and if that's all that has changed, I can't explain
it. If you had answered the questions I posed at the end of my last
message, I'd have had more to go on.
--
Doug Harrison
Visual C++ MVP
.
- Follow-Ups:
- Re: memory leak?
- From: wanwan
- Re: memory leak?
- References:
- memory leak?
- From: wanwan
- Re: memory leak?
- From: Joseph M . Newcomer
- Re: memory leak?
- From: Doug Harrison [MVP]
- Re: memory leak?
- From: wanwan
- Re: memory leak?
- From: Doug Harrison [MVP]
- Re: memory leak?
- From: wanwan
- memory leak?
- Prev by Date: Re: memory leak?
- Next by Date: Re: CFileDialog not in OS language.
- Previous by thread: Re: memory leak?
- Next by thread: Re: memory leak?
- Index(es):
Relevant Pages
|