Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ADO in multithreaded app (mem leak) problem

129 views
Skip to first unread message

Junaid

unread,
Dec 18, 2002, 2:16:11 AM12/18/02
to
Hello there

I have a strange broblem.
i am using ADO in VC6 in a multi threading MFC application
where atleast 6-15 worker threads are executing with 2-5
user interface thread.
My problem is i have to call CoInitialize in each thread
and go for connection + record set in each thread. and
this tooks not only lot of memory but also keep incressing
as the application has to run 24h a day. By using Rational
Purifier i found 2 problems.
1. it shows memory leaks in all places where i OPEN
conection + where i set recordSet.
2. Smart pointer are unable to release auto (some
inconsistance behaviour).
3. when i debug and want to c my existing threads it not
only shows the threads of my application but also shows
the ADOs threads so its imposible to debud and trace
numbers.
Couls any one help me so thay i can stop this rise in
memory or sort of huge memory leak.

Thanks in advance
Junaid

Oleg

unread,
Dec 18, 2002, 9:43:18 AM12/18/02
to
Instead of keeping a connection per thread try to use ADO connection pooling
as described in the Microsoft Technical Article "Pooling in the Microsoft
Data Access Components". Open connections only when you need them, and
dispose as soon as possible. Connection pool would keep just enough
connections to satisfy your needs. Don't forget to close recordsets and
connections when you don't need them. Otherwise the pool wood grow out of
control.

I am using ADO in a multithreaded NT service and this approach helped me a
lot.


"Junaid" <Junai...@hotmail.com> wrote in message
news:051d01c2a665$5794c330$d3f82ecf@TK2MSFTNGXA10...

Junaid

unread,
Dec 19, 2002, 12:01:58 AM12/19/02
to
This is what i am doing
-----------
CoInitialize(NULL);
ADODB::_Recordset *pRstAlr = NULL;
ADODB::_Connection *pConn = NULL;


hr = CoCreateInstance(__uuidof
(ADODB::Connection),NULL,CLSCTX_INPROC_SERVER,__uuidof
(ADODB::_Connection),(void **)&pConn);

hr = pConn->Open(_bstr_t
("UID=easy;PWD=easy;DRIVER={Microsoft ODBC for
Oracle};SERVER=love;"),_bstr_t(""),_bstr_t(""),-1);

hr = CoCreateInstance(__uuidof
(ADODB::Recordset),NULL,CLSCTX_INPROC_SERVER,__uuidof
(ADODB::_Recordset),(void **)&pRstAlr);
hr = pRstAlr->Open(_bstr_t("select * from
campaign"),pConn,
ADODB::adOpenForwardOnly,ADODB::adLockReadOnly,ADODB::adCmd
Text);
int i = pRstAlr->RecordCount;


pRstAlr->Close();

pConn->Close();
pRstAlr->Release();

pConn->Release();

pRstAlr=NULL;
pConn = NULL;
CoUninitialize();
-----------
after execution the above code it don't release mem as
shown by task manager and by perfmon.
can u pls guid me where i am making this WRONG

>.
>

Junaid

unread,
Dec 19, 2002, 2:08:00 AM12/19/02
to
Even if i do nothing simple create a connection > open it
> and then close it and make the pointer NULL. EVEN then
the resourses will not be released. even the scope of the
variables also OUT.

Any Idea????

>.
>

Oleg

unread,
Dec 19, 2002, 9:13:19 AM12/19/02
to
BTW, you don't need to Release AND assign NULL to the smart pointer. You
need to Release OR assign NULL pointer.

What resources are not being released?

ADO/ODBC libraries usually stay in (virtual) memory once they are loaded.
Try to run the part of code between CoInitialize and CoUnitialize in a loop.
Does your memory usage creeps up?

I have an application that does that and I noticed that the memory
consumption grows by 4K about every 1000 database operations. I tried
BoundsChecker and Purify and they showed no memory leaks. So I assume it is
heap fragmentation or something.

"Junaid" <Junai...@hotmail.com> wrote in message

news:046801c2a72d$5d4e61a0$d7f82ecf@TK2MSFTNGXA14...

Frank Schoondermark

unread,
Dec 20, 2002, 3:16:59 AM12/20/02
to
I am also using Rational Purifier to find memory leaks. While it is
certainly a good tool, like all memory leak tools it 'finds' memory leaks
which aren't just there. I also got it reporting memory leaks on opening a
connection even though I closed it correctly. This even happened when I
disabled connection pooling.

I did a test by doing that same step a million times, but never saw the
memory grow one byte. So I have dismissed that type of error as incorrectly
reported by Rational Purify. You should do exactly the same. Take the error
that Purify is reporting, make a simple benchmark, and if you don't see
memory growing infinite, then just dismiss it.

"Junaid" <Junai...@hotmail.com> wrote in message

news:046801c2a72d$5d4e61a0$d7f82ecf@TK2MSFTNGXA14...

Junaid

unread,
Dec 20, 2002, 4:42:35 AM12/20/02
to
Hello there

u comment on rational purifyer okay lets say u r right.
Now listen to me pls again it might help in identifying
the problem.

if i do the same stuf in VB and VC and monitor other
application by task monitor and perfmon i get the same
problem. the resources are not released by them. i am
using ADO 2.7 with oracle 8i.

when i get the dump of my objects i get some tace like
CDynLinkLibrary 64 bytes long xxxxxxxx

Then i search in MSDN i i find some artical i.e.
PRB: Memory Leaks Reported When Using Multiple MFC DLLs
in which it discuse things as a false leak in debug
version only but i am experiencing it in my release
version as well.

My problem is that the application i am developing has to
run on the main production server continusly 24h*30days+12
months

so i can't afford to lose even a single byte.

Plz help me if any one has any idea to solve this problem

otherwise any ROUND ABOUT.

special thanx in advance

JUNAID

>.
>

Frank Schoondermark

unread,
Dec 20, 2002, 10:30:47 AM12/20/02
to
I have posted my response already in a different posting on this thread, so
read the full info there.

Rule number one: Not everything Purify reports as a memory leak is in
reality a memory leak.

In other words, if you get a memory leak and can't find anything wrong then
just test that structure of code by executing it a lot and watch if your
private bytes and virtual bytes of your process keep on growing until you
get memory allocation errors. If it doesn't then Purify is wrong.

"Junaid" <Junai...@hotmail.com> wrote in message

news:06ee01c2a80c$2076dd90$d2f82ecf@TK2MSFTNGXA09...

JUNAID

unread,
Dec 24, 2002, 2:10:28 AM12/24/02
to
Respected Friends

Special thx for ur help.
i would like to close this discussion and here are my
closing statmnets

1. i tried to use ADO cos i is future and it give many
features but i found is too bad (sory to use this word)
experience using it in some sensetive, performance
oriented and 7*30*12 executing time aplication.

I never ever recamund any one to use this in such an
application. it keep on incressing memmory and .... (don't
want to comment more).

Now i am usinf simple ODBC MFC classes CDatabase,
CRecordSet and it is quite stable (still have leaks but
now my app can execute atleast for 1 month countinusly).

I might not be a perfact devloper and might not understand
COM and ADO in 100% but i don't find it a good compoonent
tto use in the presence of ODBC specially in the case of
Relational DB.

Once again special thx for ur help and pressious disscusion
my mail is
Junai...@hotmail.com
i will be glad to have u friends when ever i can do some
thing for u.

BYE and happy crismiss
JUNAID

>.
>

Valentin

unread,
Jan 4, 2003, 4:47:12 PM1/4/03
to
Hi, Oleg.
I have a similar memory leak problem in my VC++
application, Windows 2K, ADO 2.7, SQL Server 2K.
I execute the commands assynchroneously, and
close the recordset and connection, when they are not
needed anymore.
I loose about 4k / request, which never get released.
Are you using C++ and the #import directive?
Best regards,
Valentin Manolov,
Software Developer,
Tekflow MIS

>I am using ADO in a multithreaded NT service

0 new messages