Program Memory Low - Select a task to close or increase program memory

T

Tsviatko Yovtchev

I've been putting my application(C#, .NET CF) through some stress
testing when I encountered this pretty nasty problem.

Basically, when the application runs out of memory I get the "Program
Memory Low - Select a task to close or increase program memory" dialog
window with a list of running tasks that I can close to choose from. My
app, however is NOT listed there. So, if I close everything else and my
app still needs more memory I keep getting instances of this dialog
window with nothing to choose from until eventually the whole system
crashes at which point I need to do a restart.

So, it looks like I'll have to handle this problem inside my
application. The problem is I could not find a way to programatically
determine the amount of free memory at a given point of time. I also
could not find any event that occurs when there is no more free memory
which I could handle inside my app.

Does anybody have any idea how I can handle this problem?
 
T

Tsviatko Yovtchev

Hi Erwin,

Thanks for the quick reply. I've considered this approach, but the
problem with it is that it is hard find out exactly when there is
absolutely no more memory available. The garbage collector hits in at
some point and increases the amount of available memory for one thing.
So, I have to put P/Invoke calls to GlobalMemoryStatus before every
allocation which will make my code tremendously slow.

I was thinking more along the lines of some event or callback function
that occur when there is no more memory, but I could not find anything
of the kind.
 
E

Erwin van Hunen

What about running the check for memory in a separate thread and have it
check at certain intervals?

It's for sure not 'pretty' but you can you register some events and have
your thread invoke them the memory becomes critical.

/Erwin
 
T

Tsviatko Yovtchev

Yeah it is really not pretty :)

The problem is that it is not guaranteed to detect the exact moment when
the app runs out of memory. So, it would not prevent the app from
falling into the same nasty loop I described in my first message. And
that is definitely something I do not want my users to see.
 
T

Tsviatko Yovtchev

Alex said:
Why don't you run the check before your program allocates some memory?
The problem is that most of the time the memory allocations take place
inside the .NET CF classes. For example, I am running out of memory in a
loop that continuously calls SqlCEDataReader.Read(). Apparently, when
called Read() allocates some memory internally. However, when the
allocation fails it does not throw an OutOfMemoryException, so that I
can handle it. Instead the "Program Memory Low - Select a task to close
or increase program memory" dialog box is showed and the whole thing
enters in the nasty loop I described in my first post. I also have no
way of knowing how much memory Read()(or any other .NET CF metohd for
that sake) will need so that I could check in advance whether it is
available.
 

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

Similar Threads


Top