Subject: Re: Possible BUG in Garbage_collection

From: Jan Wielemaker <[email-masked]>
Date: Wed, 15 Dec 1999 14:14:43 +0100

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