Browse thread
Callback.register memory leak
- Ken McMillan
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-12-30 (02:01) |
From: | Ken McMillan <mcmillan@c...> |
Subject: | Callback.register memory leak |
I had a strange memory leak in an ocaml program that turned out to be caused by Callback.register. Perhaps this is a bit unusual, but this program registered many function closures under the same name. The intention was to override the previously registered callback under that name. However, the previously registered closures remained referenced and were not garbage collected. The problem is in caml_register_named_value: CAMLprim value caml_register_named_value(value vname, value val) { struct named_value * nv; char * name = String_val(vname); unsigned int h = hash_value_name(name); nv = (struct named_value *) caml_stat_alloc(sizeof(struct named_value) + strlen(name)); strcpy(nv->name, name); nv->val = val; nv->next = named_value_table[h]; named_value_table[h] = nv; caml_register_global_root(&nv->val); return Val_unit; } Notice that the new value in named_value_table is registered as a global root, but the previous value, if there is one, is not removed. Thus the memory leak. Best regards and thanks for a great programming tool... Ken McMillan