Re: RAII (Resource Acquisition Is Initialization) pattern limitati
- From: George <George@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 26 Dec 2007 04:57:01 -0800
Thanks David,
It is my mistake to misunderstand RAII pattern that it covers new/new[]
before. Now my question is answered.
regards,
George
"David Wilkinson" wrote:
George wrote:.
Hello everyone,
Through my testing and study of RAII (Resource Acquisition Is
Initialization) pattern, I think it can solve resource release issue in the
following two situations,
1. Local function object (on stack);
2. Object (either on heap or stack) pointer by auto_ptr;
But it has the limitation that the object pointed by a normal pointer and
allocated on heap (using new or new[]) can not be automatically released,
either the function returns normally or during exception stack unwinding. Is
that correct?
George:
If you use new or new [] without std::auto_ptr or std::vector then you
are not using RAII, and you have the potential for memory leaks. This is
not a "limitation" of RAII.
--
David Wilkinson
Visual C++ MVP
- References:
- Re: RAII (Resource Acquisition Is Initialization) pattern limitations
- From: David Wilkinson
- Re: RAII (Resource Acquisition Is Initialization) pattern limitations
- Prev by Date: Retrive Physical Media details associated with Logical Drive
- Next by Date: bad_alloc
- Previous by thread: Re: RAII (Resource Acquisition Is Initialization) pattern limitations
- Next by thread: Re: RAII (Resource Acquisition Is Initialization) pattern limitations
- Index(es):
Relevant Pages
|
Loading