最近在把TinyXML移植到Symbian平台,可是一直存在内存泄漏,经过检查,内存泄漏原因在TiXmlDocument::LoadFile()中,
如上代码所示,加上CloseSTDLIB()后,内存泄漏消失,不调用CloseSTDLIB会出现内存泄露。
必须调用CloseSTDLIB的原因是:
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.
参考:http://discussion.forum.nokia.com/forum/showthread.php?t=165359
本文详细介绍了TinyXML在Symbian平台移植过程中遇到的内存泄漏问题,并深入分析了TiXmlDocument::LoadFile()函数中导致内存泄漏的具体原因。通过加入CloseSTDLIB()函数调用来释放线程本地存储资源,成功解决了内存泄漏问题。

867

被折叠的 条评论
为什么被折叠?



