GNU bug report logs - #12095
Protecting pointer on bytevector with guardian does not protect memory

Previous Next

Package: guile;

Reported by: Patrick Bernaud <patrickb <at> chez.com>

Date: Mon, 30 Jul 2012 16:48:01 UTC

Severity: normal

Done: ludo <at> gnu.org (Ludovic Courtès)

Bug is archived. No further changes may be made.

Full log


Message #26 received at 12095 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Daniel Hartwig <mandyke <at> gmail.com>
Cc: Patrick Bernaud <patrickb <at> chez.com>, 12095 <at> debbugs.gnu.org,
	Ian Price <ianprice90 <at> googlemail.com>
Subject: Re: bug#12095: Protecting pointer on bytevector with guardian does
	not protect memory
Date: Mon, 08 Oct 2012 15:44:49 +0200
Hi,

Daniel Hartwig <mandyke <at> gmail.com> skribis:

> On 8 October 2012 04:38, Ludovic Courtès <ludo <at> 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’.




This bug report was last modified 12 years and 291 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.