Out of memory .NETCF Windows Mobile 5

2019-07-19 03:36发布

问题:

We have a .NETCF 3.5 app written in C# where we use some fairly large lists and dictionaries of objects, populated with data from a SQL Server and persisted to SQLCE databases on the device.

The app was running very well until recently. The amount of data is such that we are getting Out of memory exceptions quite frequently. Using the Hibernate event, I have confirmed that the OS is indeed asking the app to free up resources (the Hibernate event gets fired constantly). The rub is that I really do not see anything substantial that I can free up - the lists and dictionaries, etc. are all being used by the application.

I know there is a hard 32 MB / app limit in Mobile 5/6 (in reality only 18-20 MB, per http://dev.fittingsites.com/bol/2008/windows-mobile-6-1-memory-management-changes).

I am a bit at a loss here. If the app needs about 25 MB to operate, how can it run on Mobile 5? Are there workarounds, like storing lists or dictionaries in Memory Mapped Files or similar that would not require a ton of work (or slow things down much)?

回答1:

Which method are you using to read data from your SQLCE database? SQLCE provides two main approaches: DataSets and ResultSets. DataSets are known to consume huge amounts of memory and to reduce the application performance. If you are using DataSets I would recommend trying to switch your application to use RecordSets instead. See this page for more details.