Re: memory leak in the code?
- From: "Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx>
- Date: Mon, 7 Jan 2008 09:05:29 -0600
You're in the wrong group. You already know about and use the C++ group, so
stop multiposting.
And yes there would be a memory leak if the allocation for b fails. Use a
smart pointer.
<George George> wrote in message
news:20081510531george4academic@xxxxxxxxxxxx
Hello everyone,
Should I delete memory pointed by pointer a if there is bad_alloc when
allocating memory in memory pointed by pointer b? I am not sure whether
there will be memory leak if I do not delete a.
[Code]
try {
a = new int [N];
b = new int [M];
} catch (bad_alloc)
{
// if a success, but b fail, should we try to delete[] a here to avoid
memory leak?
}
[/Code]
thanks in advance,
George
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
.
- References:
- memory leak in the code?
- From: George George
- memory leak in the code?
- Prev by Date: Re: bad_alloc
- Next by Date: Re: Critical section shared betwen dll and main program
- Previous by thread: memory leak in the code?
- Next by thread: Re: memory leak in the code?
- Index(es):
Relevant Pages
|