Memory allocation purity

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Wed May 14 20:13:01 PDT 2014


On Thu, 15 May 2014 01:25:52 +0000
Kapps via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> On Thursday, 15 May 2014 at 00:00:37 UTC, Walter Bright wrote:
> >
> > Because GC failures are not recoverable, so the pure allocation
> > cannot fail.
>
> Is this intentionally the case? I always thought you could handle
> it with onOutOfMemoryError if you knew that your program could
> handle running out of memory and free some memory (i.e., cached
> data) to recover. I've never actually had a use for it myself, so
> I'm just basing this off of newsgroup discussions I remember
> (possibly incorrectly) reading.

It's intended that all Errors be considered unrecoverable. You can catch them
when necessary to try and do cleanup, but that's fairly risky, and you should
probably only do it when you're very sure of what's going on (which generally
means that the Error was thrown very close to where you're catching it).
There's no guarantee that automatic cleanup occurs when Errors are thrown
(unlike with Exceptions), so when an Error is thrown, the program tends to be
in a weird state on top of the weird state that caused the Error to be thrown
in the first place. In theory, you could catch an OutOfMemoryError very close
to where it was thrown and deal with it, but that's really not what was
intended.

- Jonathan M Davis


More information about the Digitalmars-d mailing list