Version française
Home     About     Download     Resources     Contact us    
Browse thread
let x = ... in object ...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] let x = ... in object ...
From: Guillaume Hennequin <guillaume.hennequin@epfl.ch>

> well, I have just tested this in the toplevel
> 
> class a n =
>   let x = Array.make_matrix n n 0. in
> object(self)
>   val y = Array.init n (fun i -> Array.copy x.(i))
>   method y = y
> end ;;
> 
> let mya = new a 10000 ;;
> 
> ---------> memory consumption 78.5 (from top)
> 
> Gc.full_major () ;;
> 
> ---------> memory consumption is still 78.9

Try with

class a n =
  let x = Array.make_matrix n n 0. in
object(self)
  val y = Array.init n (fun i -> Array.fold_left (+) 0. x.(i))
  method y = y
end ;;

After the gc, x is collected.
What you are seeing is the size taken by y.

Jacques Garrigue