object through a smart pointer. ATL's smart pointers are the
will allow it. You need to replace those with Release calls on the
smart pointer class itself. E.g. ->Release() becodes .Release().
Of course you should also never call AddRef either.
Hi Brian,
I have replaced all pointers by smart ones using your preference, but
nothing works now :-( strange things started to happen, unexplainable
crashes, processes don't dissappear when I destroy the instance of the
component, and so on.
Since I don't know when objects are finally released, I think that some
objects aren't released when it should be, or they are released when they
shouldn't be.
So.. I will try to modify the code so that reference counting doesn't
increase whenever I create an instance for an interface.
If I use piDynaset.Attach (piTemp, false), the reference counting is 1
until
piDynaset is destroyed (right?). So I will try to do so, because I think
that
the OO4O (Oracle Objects for Ole) are sensible regarding interface
references. This is the only thing I can think of, because by using normal
pointers, the program worked. But in that case, I cannot be sure if I
didn't
forget to release a pointer, and maybe when I deploy it in production
environment, the whole system could crash under some load, due to that
pointer still present in memory.
Jaime
"Brian Muth" wrote:
"Jaime Stuardo" <JaimeStuardo@discussions.microsoft.com> wrote in message
news:8A672FF1-94C8-42C9-86E6-12D86BB58BAD@microsoft.com...
I have the following doubt if I use smart pointers:
When I use, for example,
OO4O::OraDynasetPtr piDynaset;
m_piDatabase->GetCreateDynaset(T2COLE(lpszSQL),
0)->QueryInterface((OO4O::OraDynaset **)&piDynaset);
My coding preference:
OO4O::OralDynaset *piTemp;
OO4O::OraDynasetPtr piDynaset;
m_piDatabase->GetCreateDynaset(T2COLE(lpszSQL),
0)->QueryInterface(&piTemp);
piDynaset.Attach (piTemp);
Now for sure piDynaset is set correctly.
after the QueryInterface, piDynaset will have a reference count of 1,
right?
when piDynaset goes out of scope, it is released and the memory is
freed.
And
when the function returns, the IDispatchPtr created by GetCreateDynaset
is
released and the memory used by it is freed.
IDispatchPtr is an implied temporary variable that goes out of scope
immediately the line after GetCreateDynaset.
Can I trust 100% if I always use smart pointers, all memory will be
freed
after the component is destroyed or when I set to NULL the smart
pointer?
Your wording is bad. The component self-destructs only when all interface
pointers are released, not the other way around.
You don't need to set the smart pointer to NULL. When it goes out of
scope,
Release() is called automatically.
Brian