Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Out-of-memory faults and other cygwin issues
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Out-of-memory faults and other cygwin issues
> Does anyone know what triggers ocaml to crash on an "out-of-memory"
> error?  I'm currently using ocaml on cygwin, and I find that my program
> often crashes after the memory size reaches about ~200 megs.  This
> happened on a machine with a gig of ram and that didn't have all that
> much else running.

The Caml heap is composed of several largish blocks (about 256 Kb)
allocated with malloc().  When the heap is full, a new block is
allocated with malloc(); if this fails, the Out_of_memory exception
is raised.

Apart from this, Out_of_memory can also be raised by the structural
comparison functions (=, <>, <, etc) when their internal stack become
too large.  This can happen if you compare two cyclic or extremely
deep data structures.

You can get some insight on the cause of an Out_of_memory exception by
setting the OCAMLRUNPARAM variable to "v=63".  This causes the GC to
print a narrative trace of what it's doing.

> Another thing I've noticed is that ocaml doesn't seem to collect memory
> at the times I expect it to.  In particular, after clearing all
> references to the big memory structures and running Gc.full_major and
> Gc.collect (in that order), the memory size (as measured by the Windows
> task manager) doesn't immediately go down.  It's possible that I've
> neglected to clear my memory references, but I don't think that's it. 

When a heap block becomes empty (e.g. after GC compaction moved all
live objects to other heap blocks), this block is returned *to the C
memory allocator* by calling free().  However, many implementations of
free() will not return this memory to the OS, but rather keep it
around for later use.  In this case, external tools like the task
manager show no decrease in memory usage.

> Another odd and regrettable thing I've noticed about ocaml-on-cygwin is
> that when it crashes with a stack error, on cygwin it does so
> silently--no error message at all.  Anyone know if this is something
> that can be worked around?

ocamlopt-generated code operates on the system stack, and recovering
cleanly from a system stack overflow is very highly OS-dependent.
Currently, this is supported only under Linux/x86 and BSD/x86.  I
haven't figured out how to do it under Cygwin.

- Xavier Leroy
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: