English 中文(简体)
为解决CF外派问题提供咨询意见
原标题:Advice on solving OutOfMemoryExceptions for CF

My CF application has a very customized UI, using lots of images as UI elements. The UI feels a lot more smooth when these bitmaps are kept in memory. When they re loaded on demand, the UI is slow and I can see the buttons appearing one by one, which looks very poor. For a long time this went pretty well, but recently I ve found the application nearly uses all the memory it can get, which is 32MB iirc. I then started using the remote performance monitor to see if I could find any clear memory hogs.

As it turns out, getting a useful snapshot of the GC heap using RPM is hard: close before I m likely to receive out of memory exceptions, requesting a snapshot causes a native exception to be thrown instantly. I can manage to find a GC snapshot once in a while though. I saved one here: http://files.zzattack.org/misc/ramis.gclog and a screenshot here: http://files.zzattack.org/images/ramisgcsnapshot.png To me it doesn t look all that troublesome, by far the largest object is a byte array containing my resources file (about 3MB full of PNG images). Alltogeher, 3643304b (about 3.5MB) of memory is used. These images are spread over UI elements in about 20 different forms. I m don t know what impact seperate threads have on memory usage, but about 5-6 threads are running simultaneously, of which at least 4 are in a blocked state 95% of the time.

在该方案中,当我试图下载2MBgzipped文档时,我总是会收到外观。 当我打电话给GC.GetTotalMemory(false)时,我看到,我确实试图分配比现在更多的资金。 《使用GC》。 收集和再次试图解决我的问题。

我想就如何解决我的问题提出一些建议。 我绝对想要的是记号,但也许我可以限制用于比图的排位数,只保留最经常需要的时间,并按要求装载他人。 这很可能是一颗长枪,但也许我可以要求监督厅为我保留更多的记忆? 我确信,申请将只使用有足够长的援助团可用装置。 事先感谢任何帮助。

最佳回答

如果你以多种方式重新使用同样的图像,那么你就应考虑把这些比特图作为固定变量列入一个表格,所有表格都可以查阅。

public class AppBitmaps
{
  public static Bitmap LogoBitmap = new Bitmap(...);

  public static Bitmap ButtonBitmap = new Bitmap(...);
}

public class Form1
{
  public Form1()
  {
    this.Control1.Image = AppBitmaps.LogoBitmap;
  }
}

这样,你就只能把这种形象的一例记在记忆中,而这种形象应该减少记忆的整体使用。

问题回答

"getting a useful snapshot of the GC heap using RPM is hard" Maybe you can try some profiler for .NET CF, I have heard of EQATEC profiler if that helps you with the threads.

我避免OMOM错误的办法不是设计MDI(多功能文件接口)类型的应用,只有一种记忆形式,并在所有物体被使用后将其失效(特别是XMLDocument等“更重的”物体)。

Also, this might be relevant: OutOfMemoryException When Creating a Large Bitmap in CF.NET

如果这是对你的申请进行全线打的那枪,我建议:

  • It s another app that is running
  • Your app pinvokes into an unmanaged memory leak
  • The OS (customised CE?) has a leak
  • or something else




相关问题
How would you refactor this bit of code?

This bit of code runs on Windows Compact Framework and what it does is obvious. It looks as it should be refactored (especially considering that I may want to add cmd.ExecuteResultSet() later), but I ...

Using maps on Windows Mobile

I m experimenting with maps on different mobile platforms. Getting Google Maps to work on Android was easy, following this tutorial. Getting the same to work on Windows Mobile is a different matter. ...

Upload file to server in Windows mobile C# project

We have a setup of server and windows mobile device as a client. In server CSI script ready to accept single file from client. In Desktop we have use WebClient.UploadFile method to upload file to ...

Custom listview control for windows mobile in c#

I need to develop a custom listview control (ie, i need two labels and a progress bar in each list item) . I am new to windows mobile so please help me with code samples.

sending USSD in C#?

I want to write a simple c# application runs on windows mobile 6 which can send USSD messages Is there any library that could help me in doing this?? or is there any examples that explains how to ...

Do mobile phones have a Server : Port Scheme ?

I am new to mobile phone programming, find networking very interesting, and have this question: Does a phone running Windows Mobile or other OS s have Server:Port scheme, and what are the ports? ...

compact framework 2.0 detecting enter key in a textbox

I am developing a small app for a Motorola 9090-G using .net compact framework 2.0. My problem is that I can t seem to detect an enter keypress in a textbox. How do you detect an enter keypress in a ...

热门标签