RAII (Resource Acquisition Is Initialization) pattern limitations

G

George2

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?


thanks in advance,
George
 
B

Barry

George2 said:
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;

The name of this idiom literally suggests such usage, and of course the
"limitation"
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,

do you mean GC?

either the function returns normally or during exception
stack unwinding. Is that correct?

if you returning an auto_ptr, there's no such issue, as copy constructor
of auto_ptr guarantees no throw.
anyway, I still not quite understand what you mean.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top