Re: new char
From: Rolf Magnus (ramagnus_at_t-online.de)
Date: 10/19/04
- Next message: Victor Bazarov: "Re: map.insert(key,val) vs. map[key]=val ?"
- Previous message: Tom Widmer: "Re: Template functions and overloading"
- In reply to: SJ: "new char"
- Next in thread: John Harrison: "Re: new char"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 19 Oct 2004 18:55:11 +0200
SJ wrote:
> Hi:
>
> I am reviewing some bad code. Help me on this! The following is a
> modified version of the code.
>
> whie(some condition)
> {
> char *x;
> x = new char(' ');
> foo(x);
> }
> The variable x is not deleted. So, there is a memory leak?
If it's not deleted, yes. But are you sure that foo() doesn't delete it?
> This code sometimes crashes with a "memory could not be read" problem.
A memory leak means that you just waste memory by not freeing it after you
need it. But such a crash usually has another reason.
> Can anyone explain me the internals of how memory is handled and what
> causes the problem?
That's dependant on the platform and on the code. You might see such errors
e.g. when attempting to delete memory twice or when trying to access memory
that you didn't allocate before or that you already deallocated.
- Next message: Victor Bazarov: "Re: map.insert(key,val) vs. map[key]=val ?"
- Previous message: Tom Widmer: "Re: Template functions and overloading"
- In reply to: SJ: "new char"
- Next in thread: John Harrison: "Re: new char"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|