ODBC Memory Leak

maimang1999 2006-07-25 02:07:22
Oracle server:HP-Unix
Oracle Version: 9.2.0.6.0
Application Server: windows2003
Develop tool : VC++;

Question:
when I get the return refcursor by OLEDB.Oracle, there is not any memory leak and work well. But when I change the driver to ODBC “Oralce in OraHome92"
there will be an 56k memory leak.

And in the other hand if I call an store precedure without return ref. Both driver /way can work well.

Can you give me the advice? thanks a lot.

Code such as:
_ConnectionPtr m_AdoConnection;
_CommandPtr pcmd = NULL;
_RecordsetPtr sp_rs = NULL;

_bstr_t bstrConstruct = _bstr_t("DSN=test;Uid=test;Pwd=test;PLSQLRSet=1");
HRESULT hr = CoCreateInstance(__uuidof(Connection),NULL,CLSCTX_INPROC_SERVER,__uuidof(_ConnectionPtr),(LPVOID *)&m_AdoConnection);
if (FAILED (hr) ) throw hr ;
m_AdoConnection->PutCursorLocation(adUseClient) ;
m_AdoConnection->IsolationLevel = adXactSerializable;
m_AdoConnection->Mode = adModeShareExclusive;
bstr_t bstrEmpty(L"") ;
m_AdoConnection->Open (bstrConstruct, bstrEmpty, bstrEmpty, -1) ;

SAFE_CALL(m_spObjectContext->CreateInstance(__uuidof(Command),__uuidof(_CommandPtr),(LPVOID *)&pcmd));
if(pcmd == NULL)
throw CAtlExceptionEx(E_POINTER,"pcmd is NULL");
pcmd->CommandText = _bstr_t(L"wec_pkg_spl.wec_proc_spl_check");
pcmd->CommandType = adCmdStoredProc;

_bstr_t id = _bstr_t("65650000");
pcmd->Parameters->Append(pcmd->CreateParameter(_bstr_t(L"id"),DataTypeEnum(adVarChar),adParamInput,2000,_variant_t(id)));
pcmd->Parameters->Append(pcmd->CreateParameter(_bstr_t(L"errcode"),DataTypeEnum(adNumeric),adParamOutput,4));
pcmd->Parameters->Append(pcmd->CreateParameter(_bstr_t(L"errdescription"),DataTypeEnum(adVarChar),adParamOutput,2000));

pcmd->ActiveConnection = sp_con.m_AdoConnection;
sp_rs = pcmd->Execute(NULL,NULL,adCmdStoredProc);

pcmd->Release;
sp_rs->Close();
if (m_AdoConnection->State == adStateOpen)
m_AdoConnection->Close();




wec_pkg_spl.wec_proc_spl_check arguments:
id varchar2 in
flowpaths ref cursor out
errcode number out
errdescription varchar2 out

Message was edited by:
zwzdy199951@hotmail.com
...全文
205 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
maimang1999 2006-07-25
  • 打赏
  • 举报
回复
If my store precedure won't return the refcursor, there is no memory leak.
Otherwise, if the store precedure return the refcursor, ther is an 56k memory leak?
maimang1999 2006-07-25
  • 打赏
  • 举报
回复
thanks to healer_kx(甘草(DotNeting)) and jixingzhong(瞌睡虫:选择了远方,只顾风雨兼程!)
I had used smartpointer!

_ConnectionPtr m_AdoConnection;
_CommandPtr pcmd = NULL;
_RecordsetPtr sp_rs = NULL;
jixingzhong 2006-07-25
  • 打赏
  • 举报
回复
使用 智能指针操作,
可以确保资源正确释放:
#include <atlbase.h>
CComModule _Module;

CComDispatchDriver spDisp = ...
healer_kx 2006-07-25
  • 打赏
  • 举报
回复
有COM接口的地方,尽量用智能指针了

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧