From jan@swi.psy.uva.nl  Wed Dec 15 14:14:38 1999
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.114.15])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id OAA03322;
	Wed, 15 Dec 1999 14:14:37 +0100 (MET)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3) id OAA13707;
	Wed, 15 Dec 1999 14:14:43 +0100
Date: Wed, 15 Dec 1999 14:14:43 +0100
Message-Id: <199912151314.OAA13707@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: Possible BUG in Garbage_collection
To: Lesta@t-online.de (Uwe Lesta)
In-Reply-To: Uwe Lesta's message of Wed, 15 Dec 1999 14:00:21 +0100
Phone: +31 - 20 - 525 6121
Cc: prolog@gollem.swi.psy.uva.nl

Uwe,

> I am using prolog from a C++ application in a MS-Windows environment.
> The following occurs:
> 
> The Tail and Local Stack grow up and up  olso if I do
> explicit 'garbage_collect'.
> 
> BUT :
> If I start PL_toplevel() and do 'garbage_collect' from there
> all memory is reclaimed.
> 
> So how can I invoke correct garbage_collection with out a toplevel ? 
> 
> -----------------------------------------------
> void statistics()
> {
>     PlCall("garbage_collect");
>     PlCall("statistics");
> } // statistics;
> 
> void do_the_work()
> {
>     PlTermv av(2);
>     av[0] = PlTerm("xxxxxxxiiiiiiiiiii");
> 
>     PlQuery q("tst", av);
>     q.next_solution();
>     // do something with av[1]
> } // do_the_work
> 
> 
> ....
> 
>   if ( !PL_initialise(argc, argv) )
>     PL_halt(1);
> 
>   statistics();
> 
>   for (int i=0; i < 50000; i++)
>     do_the_work();
>   
>   statistics();
>   
> 	//   PL_halt(PL_toplevel() ? 0 : 1);
> 
> ....
> 
> prolog code :
> tst(_X, Y):-
>     A = 'tsttt',
>     Y = A.

There is nothing wrong with GC (Pfff :-).  You are faced with a builtup
of term-references.  Start your do_the_work() as

void do_the_work()
{ PlFrame fr;

  ...

And all should work fine again.  See PlFrame and PL_reset_term_refs()
for details.

	Regards --- Jan



