Clarification in memory issue
-
Thursday, December 22, 2011 10:38 AMi developed a application in C#(.netcf) and deployed to wince. when application running from SDCARD there is no problem, But when application running from flash memory iam getting out of memory exception when loading a 45MB image. for this problem iam struggling from so many days and casually i deleted few unnecessary files which will embed in exe .There after exe came from 3.63MB to 2.01MB and it works fine. I need why it behaves like that Thanks to spend some time
All Replies
-
Monday, December 26, 2011 3:11 AMModerator
Hello,
I think maybe there is no enough memory space in Mobile's RAM. It will be better that you put your application in SD card. You can also use some tools like .Net CF Remote Performance Monitor to monitor the memory use memory used.
You can follow this blog to use .Net CF Remote Performance Monitor
Finding Managed Memory leaks using the .Net CF Remote Performance Monitor
I hope these information can help you to solve this problem.
Best regards,
Jesse
Jesse Jiang [MSFT]
MSDN Community Support | Feedback to us
-
Monday, December 26, 2011 9:15 AMIam making application automatically run (i.e., flash version)along with OS. So, it will be in flash memory. I can't move it to SDCARD if it so application will not run when OS loaded. How can i know how much memory using by EXE through RPM. I tried to view in RPM but unable to view it.
- Edited by Phani564 Monday, December 26, 2011 9:16 AM
-
Tuesday, December 27, 2011 8:10 PM
I may be able to help you, but I would need to know which operating system and version you are running (Windows CE / Mobile 5.0 / 6.0 etc). This is very important to know in order to understand the memory usage.
Also.. by image... I assume you mean an OS image? Are you saying your windows image is 45 MB total?- Edited by Alan M_ Tuesday, December 27, 2011 8:12 PM
-
Wednesday, December 28, 2011 9:22 AMWINCE 6.0 R3. and Image is Bitmap not os image
-
Wednesday, December 28, 2011 3:41 PMHow much RAM does your device have?
-
Thursday, December 29, 2011 4:21 AM128MB & iam using SDCARD 2GB
-
Thursday, December 29, 2011 2:43 PM
Is it possible to break up your bitmap into smaller pieces? I think 45 MB might be just too large to fit in contiguous memory. With the issues of your program working or not, it may be just due to nuances of how much memory or what memory is being occupied. I can't think of any reason in particular other than the contiguous memory issue that you would not be able to load your image.
Maybe a topic like this will help?
http://stackoverflow.com/questions/569889/how-do-i-use-large-bitmaps-in-net
The other idea I have would be to try to create a bitmap with the GDI CreateBitmap function. When I compared CreateBitmap, CreateCompatibleBitmap, and the .NET Bitmap class on CE 5.0, calling CreateBitmap was the only way to create a bitmap outside of my process memory. Maybe this will have some advantage for you. I would try p/invoke CreateBitmap next.
private void btnCreateBitmap_Click(object sender, EventArgs e) { Graphics gfx = CreateGraphics(); IntPtr hdc = gfx.GetHdc(); IntPtr hBitmap = CreateBitmap(width, height, 1, 16, IntPtr.Zero); if (hBitmap == IntPtr.Zero) // failed to create gfx.ReleaseHdc(hdc); gfx.Dispose(); }
[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr CreateBitmap(int nWidth, int nHeight, uint cPlanes, uint cBitsPerPel, IntPtr lpvBits);- Edited by Alan M_ Thursday, December 29, 2011 2:44 PM
-
Tuesday, January 03, 2012 8:42 AMSorry for delay.... Iam using WINCE 6.0 R3. I think WINCE 6.0, there will not be an partition for a process to occupy 32 MB. That is included up to WINCE 5.0
-
Tuesday, January 03, 2012 2:47 PM
Yeah I know it doesn't and that is why I asked. I still think it is questionable that you are opening the 45 MB image on a 128 MB system. I know it sounds like it should work, but in my experience that doesn't always hold true... The reason I suggested CreateBitmap is I thought it might be worth a try just to see what happens...
If anyone else knows why it wouldn't work, I'd like to hear it myself.
- Edited by Alan M_ Tuesday, January 03, 2012 2:48 PM
-
Tuesday, January 03, 2012 2:56 PM
It may do the same exact thing, but I would look into P/Invoking this function first if you are loading a file http://msdn.microsoft.com/en-us/library/aa453720.aspx
Sometimes the managed class abstracts a lot of things from you that you don't necessarily know about. I wonder if it could be using double the memory somehow. Maybe like 45 MB to read it in to DIB bitmap and then another 45 MB of graphics memory (shared system memory) to copy it into some sort of DDB buffer, add in some O/S memory usage and maybe fragmentation and we run out of memory?
I know I'm not that much help.. but just throwing out ideas here.- Edited by Alan M_ Tuesday, January 03, 2012 2:59 PM
-
Wednesday, January 04, 2012 7:40 AMThanks for your reply & spending time for this issue I will try the possibilities. If any thing come to your mind just post it...

