* let x = ... in object ...
@ 2009-05-26 12:20 Guillaume Hennequin
2009-05-26 12:41 ` [Caml-list] " Martin Jambon
0 siblings, 1 reply; 5+ messages in thread
From: Guillaume Hennequin @ 2009-05-26 12:20 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 566 bytes --]
Dear list,
I was just wondering whether in
class a =
let x = Array.make 10000 0. in
object
val y = Array.copy x
...
end
x will be garbage collected or not.
(this is just an example, I know creating x and copying is just doesn't make
sense, but I wanted to point out that in my case, x doesn't need to be kept,
but just used during object creation. I would like it to be garbage
collected).
I roughly recall a previous post where I think the reply was "intermediate
values such as x are "kept" as members of the class", but I'm not sure.
Thanks
Guillaume.
[-- Attachment #2: Type: text/html, Size: 658 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] let x = ... in object ...
2009-05-26 12:20 let x = ... in object Guillaume Hennequin
@ 2009-05-26 12:41 ` Martin Jambon
2009-05-26 13:06 ` Guillaume Hennequin
0 siblings, 1 reply; 5+ messages in thread
From: Martin Jambon @ 2009-05-26 12:41 UTC (permalink / raw)
To: Guillaume Hennequin; +Cc: caml-list
Guillaume Hennequin wrote:
> Dear list,
>
> I was just wondering whether in
>
> class a =
> let x = Array.make 10000 0. in
> object
> val y = Array.copy x
> ...
> end
# class a = let () = print_endline "hello" in object end;;
hello
class a : object end
Maybe you mean the following:
class a () =
let x = Array.make 10000 0. in
object
val y = Array.copy x
...
end
> x will be garbage collected or not.
> (this is just an example, I know creating x and copying is just doesn't
> make sense, but I wanted to point out that in my case, x doesn't need to
> be kept, but just used during object creation. I would like it to be
> garbage collected).
> I roughly recall a previous post where I think the reply was
> "intermediate values such as x are "kept" as members of the class", but
> I'm not sure.
>
> Thanks
>
> Guillaume.
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
--
http://mjambon.com/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] let x = ... in object ...
2009-05-26 12:41 ` [Caml-list] " Martin Jambon
@ 2009-05-26 13:06 ` Guillaume Hennequin
2009-05-26 13:30 ` Martin Jambon
2009-05-27 1:46 ` Jacques Garrigue
0 siblings, 2 replies; 5+ messages in thread
From: Guillaume Hennequin @ 2009-05-26 13:06 UTC (permalink / raw)
To: Martin Jambon; +Cc: caml-list
[-- Attachment #1: Type: text/plain, Size: 812 bytes --]
> # class a = let () = print_endline "hello" in object end;;
> hello
> class a : object end
>
>
> Maybe you mean the following:
>
>
?
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
let mya = () ;;
Gc.full_major () ;;
---------> memory consumption is now 0.1
Furthermore, in a fresh ocaml toplevel,
let x = Array.make_matrix 10000 10000 0. ;;
---------> memory consumption = 39.5
(half of the previous memory usage)
So, it seems that x, although not useful after the object creation, is not
garbage collected.
??
Cheers
Guillaume.
[-- Attachment #2: Type: text/html, Size: 1213 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] let x = ... in object ...
2009-05-26 13:06 ` Guillaume Hennequin
@ 2009-05-26 13:30 ` Martin Jambon
2009-05-27 1:46 ` Jacques Garrigue
1 sibling, 0 replies; 5+ messages in thread
From: Martin Jambon @ 2009-05-26 13:30 UTC (permalink / raw)
To: Guillaume Hennequin; +Cc: caml-list
Guillaume Hennequin wrote:
>
>
>
> # class a = let () = print_endline "hello" in object end;;
> hello
> class a : object end
>
>
> Maybe you mean the following:
>
>
> ?
I was just pointing out that "class a = let x = ... in object ... end"
creates x once and for all when the class is defined, and x will therefore not
be GC'ed because of the language definition, not because of its implementation.
Martin
--
http://mjambon.com/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] let x = ... in object ...
2009-05-26 13:06 ` Guillaume Hennequin
2009-05-26 13:30 ` Martin Jambon
@ 2009-05-27 1:46 ` Jacques Garrigue
1 sibling, 0 replies; 5+ messages in thread
From: Jacques Garrigue @ 2009-05-27 1:46 UTC (permalink / raw)
To: guillaume.hennequin; +Cc: martin.jambon, caml-list
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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-05-27 1:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-26 12:20 let x = ... in object Guillaume Hennequin
2009-05-26 12:41 ` [Caml-list] " Martin Jambon
2009-05-26 13:06 ` Guillaume Hennequin
2009-05-26 13:30 ` Martin Jambon
2009-05-27 1:46 ` Jacques Garrigue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox