- Yes
- I wish (And don't even try to claim the power toys profiler will help you)
You are going to have to review your code. Make sure you are calling Dispose on all Disposable objects including all GDI objects, bitmaps, brushes.
Secondly, if you ever call Font.ToHFont, this call is extremely dangerous because it requires you to p/invoke DeleteObject to clean up after it. (A managed call requires a p/invoke to not leak resources)
My only advice is that, for some reason, most of the time my AGL errors happen close to the source of the problem. I can't remember specific causes. At work, we call this the undocumented "Accelerated Grief Layer (AGL)"
Lastly, I have one more pointed question to make. Are you allocating a lot of bitmaps at once, then freeing them, and finally trying to create managed memory objects, perhaps buffers? Windows Mobile 6 is built off of Windows CE 5.0 and not Windows CE 6.0. Therefore, each process has a 32 MB limit for memory. If you allocate a lot of bitmaps at once, they grow the size of the unmanaged heap. When you dispose of the bitmaps, LocalFree is called and the heap decommit's but does not release the memory and .NET will never see it again. The only way to avoid this, other than avoiding allocating a lot of bitmaps at once, is to allocate bitmaps that are greater than or equal to 96 KB which reserves pages outside of the heap.
Probably doubtful that is your problem, but I'll mention it because it is nearly impossible to track down. I think you would end up with a crash or OutOfMemoryException in that case, however.
Anyhow, I would look into making sure you are not leaking resources or handles, and double check your stream is in the correct format.