Is "Out of Memory" a recoverable error?

Robert Jacques sandford at jhu.edu
Tue Dec 2 07:21:30 PST 2008


On Tue, 02 Dec 2008 07:13:12 -0500, Walter Bright  
<newshound1 at digitalmars.com> wrote:
> I asked this over on stackoverflow.com to see what people using other  
> languages have to say, as well as the D community. The reason I ask is  
> to see if memory allocation can be allowed in functions marked "nothrow".
>
> http://stackoverflow.com/questions/333736/is-out-of-memory-a-recoverable-error

No.
An out of memory error from the GC is should not generally be recoverable  
inside of the current thread. (Recoverable thread (user or kernel)  
creation and termination should be supported though)

Regarding the counter examples:
I'm currently working on a D project which uses NVIDIA's CUDA platform for  
GPU computing. Instead of manually managing GPU memory, I've created proxy  
objects to leverage the D's GC. So when the GPU returns an out of memory  
error, I run a full collect and only raise an exception if it fails a  
second time. But, this isn't really and example of out of memory recovery,  
and more one of GC integration. The other examples of recovery (caches,  
free-lists, stacks/hashes without auto-shrinking, etc) are all structures  
that have their own methods of collecting/compacting memory which are  
separate from the GC and tend not to be local to the allocating function.
So people might implement something like the following:

T new2(T)( lazy T old_new ) {
     T obj;
     try{
         obj = old_new;
     }catch(OutOfMemoryException oome) {
         foreach(compact; Global_List_Of_Delegates_From_Compatible_Objects)
             compact();
         obj = old_new;
     }
     return obj;
}

Which is a decent argument for adding support for  
registering/unregistering self-collecting/compacting objects to the GC.



More information about the Digitalmars-d mailing list