out of memory问题

shuji410 2014-02-24 10:29:00
在多线程的环境中使用idhttp请求数据
以debug的方式,程序跑一会儿就提示“out of memory”,程序停在idhttp->Get()
使用的bcb版本为xe2
在windows 任务管理器中查看 程序占用内存也没有一直在增长
请问跟函数返回的类型是AnsiString及idhttp get方式相关吗?
...全文
372 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuji410 2014-03-10
  • 打赏
  • 举报
回复
好的,我研究一下C++中的auto_ptr
勉励前行 2014-03-05
  • 打赏
  • 举报
回复
try{}catch(...) 改成 try{ ih->Get(strUrl,sResponse); ih->Disconnect(); res = sResponse->DataString; } __finally { delete ih; delete sResponse; } 或者不想把异常散发出去函数,依然用try{}catch(...) try{ ih->Get(strUrl,sResponse); ih->Disconnect(); res = sResponse->DataString; } catch(Exception &e) { WriteLog(e.Message); delete ih; delete sResponse; } catch(...) { WriteLog("unknow error in CrnGetHTMLAreaText "); delete ih; delete sResponse; } return res ; 或者 你使用C++中的auto_ptr来管理内存,可避开异常问题。
shuji410 2014-02-26
  • 打赏
  • 举报
回复
因为代码比较多,也不知道贴那一块,先贴一个使用idhttp的部分

AnsiString __fastcall CrnGetHTMLAreaText(AnsiString strUrl)
{
	 AnsiString res;
	 TIdHTTP *ih = new TIdHTTP(NULL);
	 ih->HandleRedirects = true;
	 ih->ReadTimeout = 20000;

	 TStringStream *sResponse=new TStringStream();
	 try
	 {
	   ih->Get(strUrl,sResponse);
	 }
	 catch(Exception &e)
	 {
		WriteLog(e.Message);
		delete ih;
	 }

	 ih->Disconnect();
	 delete ih;
	 res = sResponse->DataString;

	 delete sResponse;
	 return res;
}
shuji410 2014-02-25
  • 打赏
  • 举报
回复
get stream有限制多大吗?
ccrun.com 2014-02-25
  • 打赏
  • 举报
回复
没有代码一切都是瞎猜。贴上关键代码look一下先。
sololie 2014-02-24
  • 打赏
  • 举报
回复
可能问题出在你用的stream,也许你get的内容太大了

13,870

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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