From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 339CE7F7AF for ; Tue, 6 Oct 2015 17:18:32 +0200 (CEST) IronPort-PHdr: 9a23:XGVQOBAVJNBMHEod3Ty3UyQJP3N1i/DPJgcQr6AfoPdwSP7zr8bcNUDSrc9gkEXOFd2CrakU16yJ6uu5CSQp2tWojjMrSNR0TRgLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpQAbFhi3DwdpPOO9QteU1JTrkb/rsMSDKyxzxxODIppKZC2sqgvQssREyaBDEY0WjiXzn31TZu5NznlpL1/A1zz158O34YIxu38I46Fp34d6XK77Z6U1S6BDRHRjajhtpZ6jiR6WYgaV6jMnTmISih9BBQ6NuBD8UJDZvSbguq9mxC6eJcj/S7ZyVTn0vIlxTxq9py4NLT809Cnsgcx9lq9B6EaurhZlwoPQJpqeNPdkc7n1ctYTRG4HVcFUAX8SSrigZpcCWrJSdd1TqJPw8h5X9UOz Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-io0-f171.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.223.171; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.223.171 as permitted sender) identity=mailfrom; client-ip=209.85.223.171; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-io0-f171.google.com) identity=helo; client-ip=209.85.223.171; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-io0-f171.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0D1AQC85RNWlKvfVdFeg3tuBrIXjW8dhX0CgS8HPBABAQEBAQEBARABAQEBBwsLCR8wgh2CBwEBAQMBEhEdARQHHQEDAQsGAwILAwoqAgIiAREBBQEcBhMJGYd2AQMKCA2OCo9MgTA+MYtJgWyCeYlTChknDVaEIAEBAQEBAQEDAQEBAQEBARUBBQ6GZYR+hGcmB4JpgUUFhziOTIsngXCaIhIjgRc4gi8MFweBVjwzAYg+AQEB X-IPAS-Result: A0D1AQC85RNWlKvfVdFeg3tuBrIXjW8dhX0CgS8HPBABAQEBAQEBARABAQEBBwsLCR8wgh2CBwEBAQMBEhEdARQHHQEDAQsGAwILAwoqAgIiAREBBQEcBhMJGYd2AQMKCA2OCo9MgTA+MYtJgWyCeYlTChknDVaEIAEBAQEBAQEDAQEBAQEBARUBBQ6GZYR+hGcmB4JpgUUFhziOTIsngXCaIhIjgRc4gi8MFweBVjwzAYg+AQEB X-IronPort-AV: E=Sophos;i="5.17,644,1437429600"; d="scan'208";a="181392606" Received: from mail-io0-f171.google.com ([209.85.223.171]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 06 Oct 2015 17:18:29 +0200 Received: by ioiz6 with SMTP id z6so224971853ioi.2 for ; Tue, 06 Oct 2015 08:18:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=i7C/gxiw3mRSe6HZ9DqvtgSsrn/O8vquKjT1r5G8nD8=; b=J88jNPYa7J6TPsHBYB3YJwK/xsMVoPC9qyq+TpQA1NECeQLyBJM3MDNRLUV56lMu4v A+sRumqUz7IgD5meyevLEyR8HDY/l8ISpIsbXjhi9Lb6940cQSchLfpORgvjAFR8Zwx1 m8wUZGTXGw1IlCjNV4ADgRVAERr03K4ncvH72GXEOMbClLt+pF+igjYs4IifQRFwKhk5 p2LRd5G5HddXL1eGjzr50WRL94D3uyzzA+vg/KGkqVgR0/xyiyLyfEC7I209BJuO2c0F HCfFL7ZVcnc0HZy0lS/3MsH+G3Hwfzs6Xi7Yw0NOrWH95j6MP+cV9lfKiwhInGJ7zEaG 0A4g== X-Received: by 10.107.170.166 with SMTP id g38mr36428372ioj.70.1444144708150; Tue, 06 Oct 2015 08:18:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.19.68 with HTTP; Tue, 6 Oct 2015 08:17:48 -0700 (PDT) In-Reply-To: <1444144145.3571.18.camel@e130.lan.sumadev.de> References: <20151006134341.GA20503@annexia.org> <20151006141625.GB20503@annexia.org> <1444144145.3571.18.camel@e130.lan.sumadev.de> From: Gabriel Scherer Date: Tue, 6 Oct 2015 17:17:48 +0200 Message-ID: To: Gerd Stolpmann Cc: "Richard W.M. Jones" , caml users Content-Type: multipart/alternative; boundary=001a11425fb4556e3b05217124f6 Subject: Re: [Caml-list] Finding "lost" references to OCaml heap values --001a11425fb4556e3b05217124f6 Content-Type: text/plain; charset=UTF-8 Sorry for the rather naive suggestion, but wouldn't it be possible to create a weak pointer in the OCaml world, and have the C value refer to that weak pointer? On Tue, Oct 6, 2015 at 5:09 PM, Gerd Stolpmann wrote: > Am Dienstag, den 06.10.2015, 15:16 +0100 schrieb Richard W.M. Jones: > > On Tue, Oct 06, 2015 at 02:43:42PM +0100, Richard W.M. Jones wrote: > > > > > > I guess I have two questions: > > > > > > (1) Is calling Gc.compact () guaranteed to call the finalizer of any > > > object which is no longer reachable, under all circumstances? Or > > > would there be some case where it wouldn't be called? > > > > > > (2) I have a large mixed OCaml / C program[a] where somehow calling > > > Gc.compact isn't calling the destructor of a (very) large object. > > > Manual code inspection has not revealed anything so far -- > > > superficially it appears we are not holding any references to the > > > object. Is there any method / library / tool that can inspect the > > > OCaml heap and find references to an object? > > > > Always good to explain these things, because the act of explaining it > > has allowed me to work out why (2) is happening now. > > > > The reason is because I was registering a global root from the C heap > > pointing to the handle, and of course this prevents the handle from > > being unreferenced. > > > > This does, however, raise another question: > > > > (3) I want to have a C heap 'value' pointing to an OCaml value, in > > such a way that if the OCaml value moves around, the C value gets > > updated to point to the new location. I was using a global root > > for this purpose, but it seems like global roots really have two > > purposes: > > > > (i) To keep the C value updated if the OCaml value moves. > > > > (ii) To act as a global root, preventing the value from being freed. > > > > Is there a "weak" global root, that has property (i) but not property > (ii)? > > There is nothing like that in the C API of the OCaml FFI. What you can > do is to keep only a symbolic reference to the OCaml value from the C > struct (i.e. if it is the k-th such value just store the number k). The > mapping from k to the OCaml value can be done with a weak hash table. > For finalizing this you need to use Gc.finalize. > > All in all this is quite complicated. I guess it's only worth it if the > memory management really needs to be fully-automatic. > > Gerd > > > Rich. > > > > -- > > Richard Jones > > Red Hat > > > > -- > ------------------------------------------------------------ > Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de > My OCaml site: http://www.camlcity.org > Contact details: http://www.camlcity.org/contact.html > Company homepage: http://www.gerd-stolpmann.de > ------------------------------------------------------------ > > --001a11425fb4556e3b05217124f6 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Sorry for the rather naive suggestion, but wouldn't it= be possible to create a weak pointer in the OCaml world, and have the C va= lue refer to that weak pointer?

On Tue, Oct 6, 2015 at 5:09 PM, Gerd Stolpmann <in= fo@gerd-stolpmann.de> wrote:
gerd@gerd-stolpmann.de
My OCaml site:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 http://www.camlcity.org<= br> Contact details:=C2=A0 =C2=A0 =C2=A0 =C2=A0 http://www.camlcity.= org/contact.html
Company homepage:=C2=A0 =C2=A0 =C2=A0 =C2=A0http://www.gerd-stolpmann.de=
------------------------------------------------------------


--001a11425fb4556e3b05217124f6--