From: "syshen" <syshen@nudt.edu.cn>
To: caml-list@inria.fr
Subject: [Caml-list] Will the data allocated by caml_alloc be automatically freed by g arbage collector?
Date: Mon, 02 Jan 2012 00:01:01 +0800 [thread overview]
Message-ID: <120102000101a0b992e1022cf562e46ade0873e35270@nudt.edu.cn> (raw)
[-- Attachment #1: Type: text/plain, Size: 1393 bytes --]
Dear All:
I am writing a program that include a main loop written in Ocaml and a sub-module written in C. The main loop called the sub-module a lot, and a huge array is returned from each call.
So I use the standard C-Caml interface to return these huge data as shown below:
extern "C" value minisat_save_proof(value unit) { CAMLparam0(); CAMLlocal1( ml_data ); vec<long>& vi=(solver->proof)->save("minisat_save_proof"); int sz=vi.size(); ml_data = caml_alloc (sz,0); for (int i=0;i<sz;i++) { Store_field( ml_data, i, Val_int((int)(vi[i])) ); } CAMLreturn( ml_data ); }
In the main ocaml program loop, there is a call to a ocaml method A, which again call this C method minisat_save_proof.
When ocaml method A got these data returned from minisat_save_proof, it call another method B to clear all data structure in the sub-module written in C, and then exit to the main loop and call Gc.compress to collect all garbage. So in this case I think the memory usage of my program should be the same like before calling minisat_save_proof , because the returned data should be collected by the garbage collector when exiting the method A to the main loop.
But from the unix "top" command, I find that these huge return data seems to remain in memory and consume all my memory step by step.
So I want to know if there is any method to free these data?
[-- Attachment #2: Type: text/html, Size: 1907 bytes --]
next reply other threads:[~2012-01-01 16:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-01 16:01 syshen [this message]
2012-01-03 14:56 ` Romain Bardou
2012-01-03 18:22 ` Xavier Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=120102000101a0b992e1022cf562e46ade0873e35270@nudt.edu.cn \
--to=syshen@nudt.edu.cn \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox