| Newsgroups |
gmane.comp.lang.ocaml.beginners |
| Message-ID |
<[email protected]> |
Everything that you've said sounds very counter-intuitive to what I've read and learned so far. If there's nothing I can do about my ocaml program running until there is no more memory or swap before dying that would be abysmally sad. From what I understand about garbage collection in the general problem, it's undecidable; garbage collectors aim just for optimal performance and good behavior in most cases. So then if there are even memory profilers for ocaml there must be some corrective action that can be taken, that's what I need to know. The pervasives library just logged a leak-they will do something about that. There has to be some kind of general practice that will allow me to keep moving forward.
Some of the other stuff about the JVM's GC you say is not what I've heard so far (JVM GC use mark and sweep?), so wouldn't dispute what algorithm it uses until I've read about it in depth. Java not using reference counting is precisely the opposite of what I've learned. Suppose I have an array which stores null or a reference to an object. If I finish working with an object, do I not mark any reference null in order to ensure that it gets garbage collected? I had an assignment once where we used a tree-set data structure to manage indexes to another reference array for fast lookup. We had to do exactly this.
On Sunday, June 28, 2015 9:17 AM, "Gerd Stolpmann [email protected] [ocaml_beginners]" <[email protected]> wrote:
Am Samstag, den 27.06.2015, 17:06 +0000 schrieb Kenneth Miller
[email protected] [ocaml_beginners]:
>
> For operations like List.map, I would imagine that the what is
> actually occurring, is a new list of equal size is being constructed
> where an operation on the old map is happening for every element. I
> would like to know what the real implications are for the garbage
> collector, and how I can minimize the performance and memory impact.
You cannot do anything, and you need not.
> Things like List.append calculate a new list by constructing a copy.
> That's incredibly inefficient to me, both in the sense that each
> element afterward (time) needs to be copied, and in that more memory
> (space) is needed.
>
>
> In addition, is there a set of advice points that can be given to make
> sure that the garbage collector will appropriately see what it needs
> to in order to free items? In java, everything is reference counted,
No, this is not true. Java, like OCaml, uses at least a mark-and-sweep
collector (of course, this depends on the JVM used, and there is
normally even a generational collector). Reference-counting is a bad
choice for any higher-level language because it cannot detect cyclic
pointer chains, and these remain uncollected.
> so if you want an object to be freed and you're maintaining it in a
> tree the lack of use of that object is better treated by going to the
> tree and updating the node that references it to mark it null. In this
> way, the garbage collector can collect the item that you were pointing
> to.
There is no need to do this (breaking cycles) in Java, and no need to do
this in OCaml.
> OCaml is a different animal though, and it doesn't use reference
> counting. There doesn't seem to me to be any simple go-to practice in
> order to ensure that the GC will in fact collect an item that I know
> at the moment because it's operation is so different.
The OCaml collector is fully automatic like the one in Java. Cycles are
collected when the whole cycle becomes unreachable.
Gerd
[Non-text portions of this message have been removed]
#yiv7360991759 #yiv7360991759 -- #yiv7360991759ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv7360991759 #yiv7360991759ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv7360991759 #yiv7360991759ygrp-mkp #yiv7360991759hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv7360991759 #yiv7360991759ygrp-mkp #yiv7360991759ads {margin-bottom:10px;}#yiv7360991759 #yiv7360991759ygrp-mkp .yiv7360991759ad {padding:0 0;}#yiv7360991759 #yiv7360991759ygrp-mkp .yiv7360991759ad p {margin:0;}#yiv7360991759 #yiv7360991759ygrp-mkp .yiv7360991759ad a {color:#0000ff;text-decoration:none;}#yiv7360991759 #yiv7360991759ygrp-sponsor #yiv7360991759ygrp-lc {font-family:Arial;}#yiv7360991759 #yiv7360991759ygrp-sponsor #yiv7360991759ygrp-lc #yiv7360991759hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv7360991759 #yiv7360991759ygrp-sponsor #yiv7360991759ygrp-lc .yiv7360991759ad {margin-bottom:10px;padding:0 0;}#yiv7360991759 #yiv7360991759actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv7360991759 #yiv7360991759activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv7360991759 #yiv7360991759activity span {font-weight:700;}#yiv7360991759 #yiv7360991759activity span:first-child {text-transform:uppercase;}#yiv7360991759 #yiv7360991759activity span a {color:#5085b6;text-decoration:none;}#yiv7360991759 #yiv7360991759activity span span {color:#ff7900;}#yiv7360991759 #yiv7360991759activity span .yiv7360991759underline {text-decoration:underline;}#yiv7360991759 .yiv7360991759attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv7360991759 .yiv7360991759attach div a {text-decoration:none;}#yiv7360991759 .yiv7360991759attach img {border:none;padding-right:5px;}#yiv7360991759 .yiv7360991759attach label {display:block;margin-bottom:5px;}#yiv7360991759 .yiv7360991759attach label a {text-decoration:none;}#yiv7360991759 blockquote {margin:0 0 0 4px;}#yiv7360991759 .yiv7360991759bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv7360991759 .yiv7360991759bold a {text-decoration:none;}#yiv7360991759 dd.yiv7360991759last p a {font-family:Verdana;font-weight:700;}#yiv7360991759 dd.yiv7360991759last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv7360991759 dd.yiv7360991759last p span.yiv7360991759yshortcuts {margin-right:0;}#yiv7360991759 div.yiv7360991759attach-table div div a {text-decoration:none;}#yiv7360991759 div.yiv7360991759attach-table {width:400px;}#yiv7360991759 div.yiv7360991759file-title a, #yiv7360991759 div.yiv7360991759file-title a:active, #yiv7360991759 div.yiv7360991759file-title a:hover, #yiv7360991759 div.yiv7360991759file-title a:visited {text-decoration:none;}#yiv7360991759 div.yiv7360991759photo-title a, #yiv7360991759 div.yiv7360991759photo-title a:active, #yiv7360991759 div.yiv7360991759photo-title a:hover, #yiv7360991759 div.yiv7360991759photo-title a:visited {text-decoration:none;}#yiv7360991759 div#yiv7360991759ygrp-mlmsg #yiv7360991759ygrp-msg p a span.yiv7360991759yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv7360991759 .yiv7360991759green {color:#628c2a;}#yiv7360991759 .yiv7360991759MsoNormal {margin:0 0 0 0;}#yiv7360991759 o {font-size:0;}#yiv7360991759 #yiv7360991759photos div {float:left;width:72px;}#yiv7360991759 #yiv7360991759photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv7360991759 #yiv7360991759photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv7360991759 #yiv7360991759reco-category {font-size:77%;}#yiv7360991759 #yiv7360991759reco-desc {font-size:77%;}#yiv7360991759 .yiv7360991759replbq {margin:4px;}#yiv7360991759 #yiv7360991759ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv7360991759 #yiv7360991759ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv7360991759 #yiv7360991759ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv7360991759 #yiv7360991759ygrp-mlmsg select, #yiv7360991759 input, #yiv7360991759 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv7360991759 #yiv7360991759ygrp-mlmsg pre, #yiv7360991759 code {font:115% monospace;}#yiv7360991759 #yiv7360991759ygrp-mlmsg * {line-height:1.22em;}#yiv7360991759 #yiv7360991759ygrp-mlmsg #yiv7360991759logo {padding-bottom:10px;}#yiv7360991759 #yiv7360991759ygrp-msg p a {font-family:Verdana;}#yiv7360991759 #yiv7360991759ygrp-msg p#yiv7360991759attach-count span {color:#1E66AE;font-weight:700;}#yiv7360991759 #yiv7360991759ygrp-reco #yiv7360991759reco-head {color:#ff7900;font-weight:700;}#yiv7360991759 #yiv7360991759ygrp-reco {margin-bottom:20px;padding:0px;}#yiv7360991759 #yiv7360991759ygrp-sponsor #yiv7360991759ov li a {font-size:130%;text-decoration:none;}#yiv7360991759 #yiv7360991759ygrp-sponsor #yiv7360991759ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv7360991759 #yiv7360991759ygrp-sponsor #yiv7360991759ov ul {margin:0;padding:0 0 0 8px;}#yiv7360991759 #yiv7360991759ygrp-text {font-family:Georgia;}#yiv7360991759 #yiv7360991759ygrp-text p {margin:0 0 1em 0;}#yiv7360991759 #yiv7360991759ygrp-text tt {font-size:120%;}#yiv7360991759 #yiv7360991759ygrp-vital ul li:last-child {border-right:none !important;}#yiv7360991759