unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Daniel Hartwig <mandyke@gmail.com>
Cc: 12095@debbugs.gnu.org, Ian Price <ianprice90@googlemail.com>
Subject: bug#12095: Protecting pointer on bytevector with guardian does not protect memory
Date: Mon, 08 Oct 2012 15:44:49 +0200	[thread overview]
Message-ID: <874nm584dq.fsf@gnu.org> (raw)
In-Reply-To: <CAN3veRd7T4hEk82Y6Dmj8inCftWN5zNWu6uf0GmN20G8ATyYqQ@mail.gmail.com> (Daniel Hartwig's message of "Mon, 8 Oct 2012 07:49:18 +0800")

Hi,

Daniel Hartwig <mandyke@gmail.com> skribis:

> On 8 October 2012 04:38, Ludovic Courtès <ludo@gnu.org> wrote:
>>>> This is expected to fail: ‘bytevector->pointer’ creates a weak reference
>>>> from the returned pointer object to the given bytevector.  So when the
>>>> pointer object is reclaimed, the bytevector can be reclaimed too, hence
>>>> the problem you’re observing.  (And no, guardians don’t protect objects
>>>> from garbage collection.)
>>>
>>> If I understand correctly, there is never any non-weak reference to
>>> the bv above and so it can be collected at any time.
>>
>> There’s a weak reference from the pointer object to the bytevector.
>>
>> Once that pointer object has been collected (as in the example above),
>> the bytevector can be collected anytime.
>
> Right.  But then the pointer is being collected even though it remains
> inside the guardian, in the example it is never extracted from there.

Well, when the object reaches the guardian’s zombie list, that’s because
it’s been finalized, so any weak references from that object can also be
nullified.

Anyway, guardians are not a mechanism to protect objects from being
GC’d.  To prevent the bytevector from being GC’d, you should either keep
the pointer object or the bytevector itself in non-GC’d memory, such as
a global variable or hash table.

How does it help?  Should we close the bug?  :-)

Thanks,
Ludo’.





  reply	other threads:[~2012-10-08 13:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-30 16:01 bug#12095: Protecting pointer on bytevector with guardian does not protect memory Patrick Bernaud
2012-08-06 16:37 ` Ian Price
2012-08-07  3:32   ` Daniel Hartwig
2012-10-06 21:41     ` Ludovic Courtès
2012-10-07  2:56       ` Daniel Hartwig
2012-10-07 20:38         ` Ludovic Courtès
2012-10-07 23:49           ` Daniel Hartwig
2012-10-08 13:44             ` Ludovic Courtès [this message]
2012-10-08 14:10               ` Daniel Hartwig
2012-10-08 15:42                 ` Ludovic Courtès

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

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874nm584dq.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=12095@debbugs.gnu.org \
    --cc=ianprice90@googlemail.com \
    --cc=mandyke@gmail.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).