Re: memory leak in small app
- From: Roland <Roland@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 30 Jan 2007 05:59:02 -0800
I think we use the included flash driver, as it is WinCE 5.0? Think it is
written by MS, I have not tested it.
I ran the Heap Walker and found that a lot of 62 byte blocks are allocated
containg the path string "\\NAND Flash Disk\\FILE.TXT". However, they are
marked as "free" in the list, so I do not know if they are a problem. Anyway,
I tried putting the path string in a const char* outside the while loop, but
it made no difference. Still clueless.
"voidcoder" wrote:
.
Asked about flushing to see if it has something
to do with the buffering. The best would be to
try CreateFile with FILE_FLAG_WRITE_THROUGH.
Also what flags are set here:
HKLM\
System\
StorageManager\
FATFS\
Flags
Btw is your flash driver tested somehow?
Roland wrote:
Thanks for the reply. I have tried with CreateFile etc, but I get the same
error there. Will try with the flush though. I will also try to create a
debug build. fwrite return the correct number of bytes written right before
the crash
"voidcoder" wrote:
The code looks fine to me. May be the problem is
somewhere within the stdlib itself. Can you try
to fflush() after each fwrite(). You may want also
also to rewrite your test using the API functions
instead. See CreateFile, WriteFile, CloseHandle.
Is it your own OS image? It may be useful to run the
same test on a debug build image, there may be some
debug output explaining the problem. Also what file
system are you using?
Btw what fwrite() is returning, have you checked the
return value.
Roland wrote:
Hello,
That's a typo, should be list[i]. Don't know why it dissapeared during the
copy.
"voidcoder" wrote:
for ( i = 0; i < 1024; i++ )
list = 'z';
Is this a typo or your code really looks
like this? You are killing the "list"
pointer this way.
Roland wrote:
Hello,
I have written an app for testing the lifetime of a flash memory, for WinCE
5.0. It goes as this:
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
FILE *stream;
char list[1024];
int i, numread, numwritten, iteration;
iteration = 0;
while (true)
{
iteration++;
if( (stream = fopen(" \\NAND Flash Disk\\FILE.TXT", "w+t" )) != NULL )
{
for ( i = 0; i < 1024; i++ )
list = 'z';
numwritten = fwrite( list, sizeof( char ), 1024, stream );
if (iteration % 10)
{
// write longer file
numwritten = fwrite( list, sizeof( char ), 1024, stream );
numwritten = fwrite( list, sizeof( char ), 1024, stream );
numwritten = fwrite( list, sizeof( char ), 1024, stream );
numwritten = fwrite( list, sizeof( char ), 1024, stream );
numwritten = fwrite( list, sizeof( char ), 1024, stream );
numwritten = fwrite( list, sizeof( char ), 1024, stream );
}
fclose( stream );
Sleep(50);
}
else
return -1;
}
return 0;
}
However, after a while WinCE runs out of memory, indiciating a memory leak.
I cannot possibly see where the memory leak is, as fclose() should free the
memory and the same char buffer is used for each iteration. Am I missing
something obvious? Btw, anyone know of a good memory profiling tool for WinCE?
/ Roland
- Follow-Ups:
- Re: memory leak in small app
- From: voidcoder
- Re: memory leak in small app
- References:
- memory leak in small app
- From: Roland
- Re: memory leak in small app
- From: voidcoder
- Re: memory leak in small app
- From: Roland
- Re: memory leak in small app
- From: voidcoder
- Re: memory leak in small app
- From: Roland
- Re: memory leak in small app
- From: voidcoder
- memory leak in small app
- Prev by Date: Tray Icon problem on startup
- Next by Date: Re: memory leak in small app
- Previous by thread: Re: memory leak in small app
- Next by thread: Re: memory leak in small app
- Index(es):
Relevant Pages
|