Out of memory exception problems

  • Thread starter Peter Morris [Droopy eyes software]
  • Start date
P

Peter Morris [Droopy eyes software]

I am experiencing out of memory exceptions in my application. For example

1) User starts importing data.
2) This takes about 30 minutes. The user gets bored and opens something
like the Start->Programs window
3) My apps gets an OutOfMemoryException thrown

If I look in the system->memory at this point it reveals that I have 7MB of
RAM available.

My app is due to go live at the end of October, can anyone offer any
suggestions?



Thanks

Pete
 
P

Peter Morris [Droopy eyes software]

More information: The problem is *always* here

at Microsoft.AGL.Common.MISC.HandleAr()
at System.Windows.Forms.Control._InitInstance()
at System.Windows.Forms.Control..ctor()

The control in question is always a descendant of UserControl, but is not
always the same user control. I can reproduce this more often if I open
file-explorer and select a few folders when the control is being created.
 
P

Peter Morris [Droopy eyes software]

More information:

If I leave my app to import then the current control on the form is updated
about 5 times per second for 45 minutes without any problems. If I leave
the File Manager open at the same time + various other apps I still have no
problems.

However, if I continually select / deselect multiple files in the File
Manager application I can get an out of memory exception in a matter of
seconds, I believe it occurs if I select a folder at the same time my user
control is created.

Therefore I can only conclude that I am not actually running out of memory.
Maybe WinCE is screwing up some kind of resource allocation when my UI
requires a handle at the same time as another app? I tried a loop like so

int triesLeft = 20;
while (true)
{
triesLeft--;
try
{
return UIFactory.Instance.CreateControl(currentObject);
}
catch (OutOfMemoryException outOfMemoryException)
{
if (triesLeft = 0)
throw outOfMemoryException;
GC.Collect();
Thread.Sleep(500);
}
}

But once the exception occurs it will keep occurring every time!

Can anyone shed any light onto this peculiar behaviour?


Thanks

Pete
 
P

Peter Morris [Droopy eyes software]

Hi José

It would seem that the problem is something to do with creating controls
whilst the user uses other applications. The problem was this

1) My app starts importing data
2) The app updates the UI every 500 milliseconds
3) Each time the UI is updated I do this
3A) Remove the only control from my form + dispose it
3B) Get a factory to create a control for the "current object" I want to
display
3C) Add that control to my form

(I only have 1 form in my app, but lots of user controls)
4) Loop #3

Now the user goes and opens the program manager and starts moving between
folders, or maybe the user keeps checking the memory and/or battery levels,
and this is what causes the problem.

My app can run happily if the user doesn't touch any other apps. It can
also run to completion if I open every app on the PPC I can find and then
run it. If however the user is "using" the apps then the following fails:

at Microsoft.AGL.Common.MISC.HandleAr()
at System.Windows.Forms.Control._InitInstance()
at System.Windows.Forms.Control..ctor()

It seems that merely selecting / unselecting folders in the program manager
repeatedly triggers this bug. Then even if trap OOM exceptions + add a
Thread.Sleep + try again it makes no difference even if I close all other
running apps. Once the control creation has failed once the app is doomed
to fail at creating any controls at all from that point onwards.

My solution was pretty crappy, but it seems to work. The event that
triggers the UI change no longer does that, instead it does this

1) Event triggered
2) GuiTimer.Enabled = true (interval is 100ms)
3) GuiTimer_Tick updates the GUI

It seems that updating the GUI from a timer rather than directly from my
code does the trick (fingers crossed).


Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top