Re: Handling Out Of Memory

From: Bruce Roberts (ber_at_bounceitattcanada.xnet)
Date: 03/31/04


Date: Wed, 31 Mar 2004 10:04:55 -0500


"Skybuck Flying" <nospam@hotmail.com> wrote in message
news:c4edjc$db3$1@news2.tilbu1.nb.home.nl...

> NO, RIGHT, VERY RIGHT :)

Very, very wrong. But before I go on, would you PLEASE clip your quotes. Its
quite annoying to have to scroll through the entire history to get to your
comments.

When writing support routines they should only ever handle a particular
exception if they can cope with it without affecting higher levels of code.
In my experience having any level of code unconditionally trap all
exceptions is very poor design. In the long run it just makes a program much
more difficult to maintain. In the short run it usually makes a program
(apparently) randomly unstable.

In the example being discussed a tree that runs out of memory can't continue
to function properly hence it can not continue to operate correctly which in
turn means that it can't cope with the exception transparently. IOW higher
levels of code must find out about the condition. So it makes absolutely no
sense for the tree to hide the condition from the code that uses it.

> I want to write an application that does know when memory is short and
that
> keeps functioning perfectly.

So write it such that it tests for available memory before attempting to
allocate it. And remember that the application is not the only active task
that needs memory. By the time an out of memory exception is raised it
generally far too late to perform any kind of graceful recovery.



Relevant Pages

  • Re: How to troubleshoot bugchecks on my own?
    ... not a memory problem. ... From that exception record and context, ... execute the instruction - without a problem. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Bsod irql_not_less_or_equal
    ... *** Memory manager detected 2 instanceof page corruption, ... likely to have memory corruption. ... the driver/function that caused the problem. ... The exception code that was not handled ...
    (microsoft.public.windows.vista.performance_maintenance)
  • Re: Strange sudden shutdown issue with CF app
    ... Phone devices are notoriously low on virtual memory right out of the box because the OEMs decide to put every little thing into its own DLL and then have 25 processes launched at boot. ... Chris Tacke, Embedded MVP ... We have created an app that basically connects to a web service gets data, then stores it locally on the device, and when a record needs to be modified/added the system first tries to connect the web server sees if its availible, if not then it stores in locally on the device until the connection comes back, now I noticed that if the device does not mess around with the data connection then the application sits nicely as long as its open, and never gets shut down. ... But again most of the time I get no exception at all but just simply disappears. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: error wince600 boot message after dowload PB6 OS to HW board
    ... I would suspect that you have a memory layout problem, either the bootloader is using memory that is clobbering the downloaded image in some way, or the memory layout in the config.bib is wrong. ... Old or invalid version stamp in kernel structures - starting clean! ... Exception 'Access Violation': Thread-Id=00410002, ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Strange sudden shutdown issue with CF app
    ... Phone devices are notoriously low on virtual memory right out of the box because the OEMs decide to put every little thing into its own DLL and then have 25 processes launched at boot. ... Chris Tacke, Embedded MVP ... We have created an app that basically connects to a web service gets data, then stores it locally on the device, and when a record needs to be modified/added the system first tries to connect the web server sees if its availible, if not then it stores in locally on the device until the connection comes back, now I noticed that if the device does not mess around with the data connection then the application sits nicely as long as its open, and never gets shut down. ... But again most of the time I get no exception at all but just simply disappears. ...
    (microsoft.public.dotnet.framework.compactframework)