Problem occurs when using std C library in Symbian
| Tue, 2005-02-01 04:22 | |
|
Hi,
Could somebody explain to me why the environment reports memory leaks during the debugging? __UHEAP_MARK; FILE* aFile = fopen("c:\\system\\logs\\mylog.txt", "rb"); // aFile is not empty here fclose( aFile ); __UHEAP_MARKEND; // Panic this line I put this into a very simple UI application and it reported memory leaks. Why? ![]() Br Martyn |
|







Forum posts: 7
Br
Martyn
Forum posts: 176
The reason why you are experiencing a memory leak at this point is because there is memory being allocated that needs to be explicitly cleaned up when using the Symbian version of the C standard library. Give this a tryÂ…
#include <libc\sys\reent.h>
__UHEAP_MARK;
FILE* aFile = fopen("c:\\system\\logs\\mylog.txt", "rb"); // aFile is not empty here
fclose( aFile );
CloseSTDLIB();
__UHEAP_MARKEND; // Panic this line
Here is a quote from the SDK documentation that discusses this in more detail
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
Darin Dishneau
www.dishneau.com/symbian
Forum posts: 7
Br
Martyn
Forum posts: 109
i am trying to do exactly what you describe, but when compiling my project with CloseSTDLIB(); , the compiler says:
8<-------------------------------------
Errors caused tool to abort.
Link Error : Undefined symbol: '_CloseSTDLIB'
Link Error : referenced from 'CQP_DatatestAppUi::~CQP_DatatestAppUi(void) (??1CQP_DatatestAppUi@@UAE@XZ)' in QP_DATATESTAPPUI.cpp:259
Link Error : Link failed
8<-------------------------------------
What did I miss?
Thanks, Marcel
Forum posts: 88
Forum posts: 109
Of course!
Thanks for the hint.
Marcel
Forum posts: 114
Forum posts: 11