From p.singleton@keele.ac.uk  Sat Feb  5 03:31:35 2000
Received: from mail11.svr.pol.co.uk (mail11.svr.pol.co.uk [195.92.193.23])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id DAA06292
	for <prolog@swi.psy.uva.nl>; Sat, 5 Feb 2000 03:31:35 +0100 (MET)
Received: from modem4294967272.events.dialup.pol.co.uk ([195.92.2.24] helo=keele.ac.uk)
	by mail11.svr.pol.co.uk with esmtp (Exim 3.13 #0)
	id 12Gv0o-0005hI-00
	for prolog@swi.psy.uva.nl; Sat, 05 Feb 2000 02:31:50 +0000
Message-ID: <389B8B45.87D531A8@keele.ac.uk>
Date: Sat, 05 Feb 2000 02:30:29 +0000
From: Paul Singleton <p.singleton@keele.ac.uk>
Organization: SmartArts Computing Consultancy
X-Mailer: Mozilla 4.7 [en] (WinNT; I)
X-Accept-Language: en
MIME-Version: 1.0
To: SWI Prolog <prolog@swi.psy.uva.nl>
Subject: garbage-collecting foreign object refs with lemmas
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

(Using the new PL_agc_hook, I can represent references to foreign
objects by atoms, then clean them up as appropriate when these atoms
are garbage collected and my cleanup routine is notified)

I want, however, to maintain lemmas about these foreign objects,
indexed by their atoms, without thereby ensuring that they are never
recovered because the atom is still around, if you see what I mean.

Is it feasible to, effectively:

 assert( java_object_type('J#0152375280',class([java,util],['Date'])))

 PL_unregister_atom('J#0152375280')

to fudge the atom reference count so that the occurrence of the atom
in the asserted fact is disregarded for GC purposes?

Is this safe, or can it be otherwise done safely?

When my agc_hook callback is called back, I want to retract all such
facts involving the atom in question.

NB I'm tempted to

  assert( +Fact, -Reference)

then associate the Reference with the magic atom in some foreign table,
and eventually PL_erase(+Record) it:

 * is it the same Reference/Record in Prolog and foreign code?

 * will this be usefully quicker than calling back into Prolog
   to do e.g. a retract?

If this isn't feasible, I may represent foreign objects by a structure
which contains both a magic atom and a corresponding integer, and use
the integer to retrieve cached info about the object, but this is a bit
clumsier...

Paul Singleton

