[Mono-list] Memory leak

Jon Harrop jon at ffconsultancy.com
Sat Jan 31 22:22:02 EST 2009


Boehm's documentation about the GC used in Mono says that memory consumption 
is "unbounded", meaning that the VM may leak indefinitely until the computer 
runs out of memory. Based upon Boehm's description of the problem, I thought 
it would be interesting to try to devise a program that leaks indefinitely 
and I came up with the following (F#):

type 'a cell = { content: 'a; mutable next: 'a cell option }

do
  let mutable tail = None
  if tail = None then
    let cell = { content = [||]; next = None }
    cell.next <- Some cell
    tail <- Some cell
  while true do
    let tail' = Option.get tail
    let cell = Some { content = [|1.;2.;3.;4.|]; next = tail'.next }
    tail'.next <- cell
    tail <- cell
    let tail' = Option.get tail
    tail'.next <- (Option.get tail'.next).next

This code creates a queue represented by a cyclic list and repeatedly adds and 
takes one element at a time (so there are always either 1 or 2 elements in 
the queue). Running on Mono 2.2, this program leaks, consuming all 4Gb of my 
memory in only 60 seconds.

I have rewritten the code in many different forms, using separate functions, 
altering the scopes of variables, making "tail" immutable and Mono 2.2 always 
leaks until the program dies. So it appears that a broad class of programs 
are leaking.

I understand that Mono's new garbage collector has been delayed until Mono 2.9 
but someone else mentioned that even this new GC will still not be accurate 
and, therefore, is likely to leak memory indefinitely as well. Is that 
correct?

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e


More information about the Mono-list mailing list