Symbian下tinyXML的内存泄露问题

来源:互联网 发布:跑鞋矩阵2017 编辑:程序博客网 时间:2024/05/17 12:52

1. 在Symbian 9.1/S60_3rd_MR_2平台初使用tinyXML读取配置文件, 基本使用其最简单的功能,代码如下:

 

    TiXmlDocument doc(wsName);
    if (!doc.LoadFile())
    {
     return -1;
    }

    TiXmlElement* pElem = doc.RootElement();

 

    开始测试时发现退出应用时,总暴出Alloc泄露问题。初始并未地意问题,到最后,主功能完成之时,不得不去解决。开始用屏蔽方法,逐渐的发现屏蔽上述代码之后,泄露问题会不存在。断定可能在tinyXML存在泄露问题,但转念想到tinyXML多么成熟的代码,会犯如此低级错误吗?

    感谢同事提供的信息,使用HookLogger来测定泄露位置,同事感谢Symbian开发如此好用的工具(比我以前所在公司开发的泄露检测工具好很多).HookLogger定位于tinyXML中fopen( filename, mode )函数。再次百度,需要使用CloseSTDLIB(),理由如下 。在打开文件后,调用上述函数,fopen函数泄露已经去掉,但在QueryIntAttribute函数附近还存在,原因使用sscanf函数。我不得不将CloseSTDLIB()移到TiXmlDocument 中析构函数中,再次运行内存泄露已经远离我而去。不暴错误的感觉真是太好.

 

提示:

Because the data allocated in the thread-local storage for STDLIB's DLL (the _reent structure) is not automatically cleaned up when the environment is destroyed, it must be cleaned up by the user of STDLIB.

The function to achieve this is CloseSTDLIB(). To use this function, file epoc32/include/libc/sys/reent.h should be included in the project. Call CloseSTDLIB() after the point at which it is known that code in STDLIB's DLL will no longer be called and its thread-local storage no longer needed.

原创粉丝点击