[eclipse-clp-users] memory leak

From: Stephan Schiffel <stephan.schiffel_at_...69...>
Date: Thu, 29 Jan 2009 14:41:40 +0100
Hello everybody,

I'm trying to find a memory leak in one of my C programs that uses ECLiPSe.
It seems that memory allocated for a ec_ref is not freed during garbage 
collection. In the example program below each call to function f() adds 
another 156 kB of used memory that is only freed in ec_cleanup().

To make things more complicated embedding ECLiPSe into C doesn't seem to work 
with the recent versions of ECLiPSe. With version 5.10_147 I get the 
following output:
calling an undefined procedure 
cd_if_possible("/usr/local/packages/eclipse-5.10_147/lib/suspend.eco") in 
module sepia_kernel
iteration 0
Segmentation fault

With version 6.0_58 the program exits after printing:
inconsistent procedure redefinition in tool_((<) / 2, (<) / 3, sepia_kernel)

Regards,
Stephan

// ====================================
// example program
#include "eclipse.h"
#include "stdlib.h"
#include "stdio.h"
#include "unistd.h"

void f(){
	int i;
	ec_ref ref=ec_ref_create_newvar();
	pword t=ec_nil();
	for(i=0;i<10000;++i){
		t=ec_list(ec_nil(),t);
	}
	ec_unify(ec_ref_get(ref), t);
	ec_post_goal(ec_term(ec_did("writeln",1),ec_ref_get(ref)));
	ec_ref_destroy(ref);
	ec_post_goal(ec_term(ec_did("garbage_collect",0)));
	ec_resume();
}

int main(){
	int i;
	ec_set_option_ptr(EC_OPTION_ECLIPSEDIR, getenv("ECLIPSE_DIR"));
	ec_init();
	for(i=0;i<10;++i){
		printf("iteration %d\n",i);
		f();
		sleep(2);
	}
	printf("ec_cleanup\n");
	ec_cleanup();
	return 0;
}
// ====================================
Received on Thu Jan 29 2009 - 14:21:08 CET

This archive was generated by hypermail 2.3.0 : Tue Apr 16 2024 - 09:13:20 CEST