.NET CF Application and Out of Memory Exception

I am developing a .NET CF 3.5 network game. My problem is the application is loading all resources into the first instance. However, on subsequent launches, the application saves me from being excluded from memory when loading resources, especially sounds or large images.

Please notify you

+1


source to share


5 answers


I am assuming that you are not trying to use multiple instances of the game at once. It looks like the memory is not being returned to the OS after your game is shut down. One easy way to determine if you have a leak:

  • Reboot your device
  • Check memory usage
  • Start your game, play it for a few minutes.
  • Close the game
  • Wait a few minutes, then check the memory usage again.


If you can run multiple launches before you run out of memory, you will have a small leak. If you can only run it once before rebooting your device, you have a BIG one. Garbage collection will only go on until now. If you are making any calls to unmanaged code (Win32 or PInvoke calls that create unmanaged objects), then you should make sure to release those resources when your game shuts down.

+2


source


How much memory does your application take after loading all resources? At default settings, I get this error reaching around 1.3GB private bytes (task manager check and process memory allocation).



0


source


Microsoft provides us with the CLR Profiler, a tool to analyze the behavior of your managed application, which you can download here . This is the CLR Profiler for .NET 2.0, but it will work with .NET 3.5 since the CLR has not been changed.

0


source


Perhaps the problem is that .NET CF does not handle the Windows CE memory model very well. (Large memory allocations crash with OutOfMemory, even though it's available, I don't know the magic number where things start to break ...)

Here are some of the details: .NET Compact Framework Advanced Memory Management

The easiest way to get around this is to copy things to the RAM disk (eg \ temp); plan B is to use something reference Marshal.AllocHGlobal or P / Invoke VirtualAlloc (scary!) along with GCHandle.Pin

0


source


Based on your programming experience with .NET CF, you are running into memory constraints and garbage collection is not what you would expect in a normal desktop / PC environment.

In my application, always calling the Close () and Dispose () methods before the objects went out of scope resolved the issues I encountered with out of memory exceptions.

If you still have problems, another way to try is to connect to your application close event handler and call GC.Collect (). This will cause the garbage collector to immediately collect any unused or located objects.

0


source







All Articles