Windows 7 - Program memory usage in Windows CE 5.0

Asked By embedinfo on 14-Aug-08 04:11 AM
Hi there,

I have a question on Program memory usage in Windows CE 5.0. When I
copy a file from one location to another on the device I see incerase
in program memory usage. (For example from MyDocuments to Desktop).
But if I delete the same file from desktop and recycle bin, I don't
get back the memory allotted during the copy. Is this memory leak in
Windows CE 5.0 filesystem? If not why Windows CE behaves like this?
Who uses that memory? How to avoid this happening?

Any inputs will be helpful!

Thanks




Michael Salamone replied on 11-Aug-08 08:44 AM
Does the memory usage grow with each operation or just the first one?

What file system do you have mounted as root?  Is it object store
(RAM-backed) or flash or ?

--
Michael Salamone, eMVP
Entrek Software, Inc.
www.entrek.com
embedinfo replied on 14-Aug-08 04:11 AM
On Aug 11, 5:44=A0am, "Michael Salamone" <mikesa#at#entrek#dot#com>

Hi,
Yes it grows for every operation (some times it increases by 12KB,
next time if you copy the same file it increases by 4 KB. The
increment is random), but it doesn't grow by file size. My platform
has flash memory and I have mounted flash disk as root and using hive
and ROM filesystem. Is there anyway I can avoid it?
This is critical issue. Any inputs will be really helpful!

Thanks
embedinfo replied on 14-Aug-08 04:11 AM
.

Hi,

I am using FATFS. Similar behaviour is seen on Emulator platform as
well. Is this memory leak in filesystem? Some times I have seen that
usage of program memory increment stops also after copying the same
file several times (may be 3-4 times). But if I copy some other file
and delete again it increses.

FYI,
I have set FRAMPERCENT=3D 128KB (minimum).

Steps to reproduce:
1) Build Emulator platform.
2) Check original Program memory usage using Control Panel-->System
applet.
2) Copy some file from Windows directory to desktop (copy a file more
than 10K size)
3) Observe the change in INUSE program memory.
4) delete the file. File will be moved to recycle bin. and observe the
memory status.
5) Delete the file from recycle bin as well and check the memory
status. It will not come to original state (I mean what you observe in
step 2)

Note: While I test this, I dont do any other operation.

Thanks
Ro replied on 12-Aug-08 02:22 AM
Hi,
Write a program that copies files periodically.
Check the remote tools to see if memory usage keeps increasing over time.
This also excludes explorer from your test.

If the mem-usage increase is just limited and does not keep increasing ,
there is no problem. Maybe youré looking for a problem that does not exist.

Greetings,
Rob
embedinfo replied on 16-Aug-08 09:13 PM
ist.
e?
om....
I
rase
).
't
in
s?

Hi,

As per your suggestions I wrote simple application to copy move and
delete file, without opening explorer. Here is my program:

// FileCopyDelApp.cpp : Defines the entry point for the console
application.
//



int _tmain(int argc, TCHAR *argv[], TCHAR *envp[])
{

//Copy files from Temp directory to Desktop
if(!CopyFile(L"\\Temp\\test.mp3",L"\\Windows\\Desktop\
\test.mp3",FALSE))
RETAILMSG(1, (TEXT("\n Failed to copy the file error:
%d"),GetLastError()));
Sleep(500);

//Move the files to My Documents
if(!MoveFile(L"\\Windows\\Desktop\\test.mp3",L"\\My Documents\
\test.mp3"))
RETAILMSG(1, (TEXT("\n Failed to copy the file error:
%d"),GetLastError()));
Sleep(500);

//Move files from My Documents back to Desktop
if(!MoveFile(L"\\My Documents\\test.mp3",L"\\Windows\\Desktop\
\test.mp3"))
RETAILMSG(1, (TEXT("\n Failed to copy the file error:
%d"),GetLastError()));
Sleep(500);

//Delete the files
if(!DeleteFile(L"\\Windows\\Desktop\\test.mp3"))
RETAILMSG(1, (TEXT("\n Failed to delete the file error:
%d"),GetLastError()));

return 0;
}

I have kept the the application on desktop and copied the test file to
Temp directory using activesync. Since I BSP supports presistent
storage, even I reboot my device files will be present. After
rebooting device i connected remote performance viewer to check memory
statistics and then started application and other than this I am not
running any application. And control panel --> system applet shows
following values. (I have opened control panel app before running the
app.

I =96 Iteration (Executed application multiple times in each iteration)
In use Storage memory  In use Program Memory
60                      17164 kb
=91=92                        17348
Kb
=91=92                        17348 Kb
=91=92                        17352 Kb
=91=92                        17348 Kb
=91=92                        17356 kb
=91=92                        17356 kb
'=92                        17360 Kb
=91=92                        17364 Kb
=91=92                        17364 Kb
=91=92                        17368 Kb
=91=92                        17368 Kb

II - Iteration
60                      17160 Kb
=91=92                       17340 kb
=91=92                       17344 kb
=91=92                       17348 Kb
=91=92                       17352 Kb
=91=92                       17352 Kb
=91=92                       17360 Kb
=91=92                       17364 kb

I observed that almost there is 200Kb of memory leak. I read in the
forum that Windows CE garbage collection is slow. But I observed that
in use program memory never comes back to original value (17160KB). I
would like to know the reason for this. If I do file copy deete
operations multiple times, program memory in use increases
cumulatively!

is there any way i can fasten the Windows CE garbage collection? Any
inputs will be helpful!

Thanks
Ro replied on 15-Aug-08 02:46 AM
Hi,
If you close your program the memory also does not return to  the original
value ?

AFAIK, there is no garbage collection.
(confirm anyyone?)
Memory fragmentation is another issue.
See : http://www.linuxjournal.com/article/6679

I see you use Copy,Move and delete, first try with just 1 (just copy) to
zoom in on the problem. Not sure from your data how many iterations you did
(60-70?), try 10.000 and see what happens.

Write your own Copyfile() using fopen,fread,fwrite,fclose.
These functions are so basic I would be very surprised if there was a
problem with these.

Greetings,
Rob.
embedinfo replied on 19-Aug-08 01:33 AM
nal
id
ime.
g ,
t exist.
t one?
tore
ps.com....
When I
incerase
ktop).
don't
leak in
this?
,
rm
hive
t
e
re
the
in
error:
uments\
esktop\
7164 kb
=A0 =A017348
=A0 =A017348 Kb
=A0 =A017352 Kb
=A0 =A017348 Kb
=A0 =A017356 kb
=A0 =A017356 kb
=A0 =A017360 Kb
=A0 =A017364 Kb
=A0 =A017364 Kb
=A0 =A017368 Kb
=A0 =A017368 Kb
7160 Kb
=A0 =A0 17340 kb
=A0 =A0 17344 kb
=A0 =A0 17348 Kb
=A0 =A0 17352 Kb
=A0 =A0 17352 Kb
=A0 =A0 17360 Kb
=A0 =A0 17364 kb

Hi,

I did some more analysis on this issue. I observed that the memory
leak is occurs due to two reasons:

1) Just by opening Widows explorer, program memory usage increases and
this memory is never given back even on closing the explorer (This was
observed on emulator as well; This issue can be reproduced just by
clicking on MyDevice and then close explorer)

2) In my BSP I am using ROM-only filesystem. And I observed that
adding this component also introduces considerable amount of memory
leak (around 200KB of memory is lost due to this when we copy, paste a
file). Does anyone know what this does? How does this component
affects program memory usage?

FYI,
I have added FSROMONLY catalog and my flash drive is mounted as root.