Hello dear hackers ! I'm using guile in an C program that spawn a lot of short lived threads, each of which passing in guile mode (guile 1.8.7), and I'm facing a memory leak even when the threads does nothing (ie. the C function called by scm_with_guile consists only of a return NULL. After some time, if I call a gc-stats I have many many segments of 21Mb allocated, although gc-live-object-stats reports that almost nothing is alive (acording to expectations).
I am under the impression that some of these segments, created by a now defunct thread, can not be reused by others. So I made a small program that continuously creates thread and run a NOP scm_with_guile in it, and then join it (so that thre thread local storage itself is not leaked). With the useless scm_with_guile call, this programm leaks memory very quickly. Comment out the scm_with_guile call and there is no more leak. What do you think ?
CFLAGS += $(shell guile-config compile) -std=c99 CPPFLAGS += -D_GNU_SOURCE LDLIBS += $(shell guile-config link) -lpthread all: many_threads clean: rm -f *.o many_threads
#include <unistd.h> #include <pthread.h> #include <time.h> #include <libguile.h> static void *thread_with_guile(void *null) { return NULL; } static void *the_thread(void *args) { (void)scm_with_guile(thread_with_guile, NULL); // comment me to remove the memory leak return NULL; } int main(void) { // We create many threads while (1) { pthread_t ptid; pthread_create(&ptid, NULL, the_thread, NULL); void *ret; pthread_join(ptid, &ret); } return 0; }