unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Chris Vine <chris@cvine.freeserve.co.uk>
To: 19236@debbugs.gnu.org
Subject: bug#19236: load-compiled procedure leaks memory
Date: Sun, 30 Nov 2014 23:30:09 +0000	[thread overview]
Message-ID: <20141130233009.0e596015@bother.homenet> (raw)

The load-compiled procedure leaks memory in guile-2.0.11 as
demonstrated by the attached test case.  It should be used in
conjunction with a file 'test-file.scm' which contains only a single #f
expression.  This test case should be invoked either with the "pload"
or "load" option.  If invoked with the pload option, it will invoke
primitive-load, which accumulates no additional memory while executing,
and will execute normally to the end of its iterations.  If invoked
with the load option, on my 32-bit machine it will steadily accumulate
a memory leak before running out of memory on consuming approximately
300M memory, after about 65,000 iterations.  The memory leak seems to
arise in guile's load-compiled procedure.

The question which might be asked is "Would any sane person ever want
to invoke the load (or load-compiled) procedures more than a few times
in a practical program?".  The answer to this question is "Yes", if
guile is being used as an extension framework for a C or C++ program,
and it executes guile extensions as individual tasks.

Test case:

----------------------------- snip -----------------------------

/* compile with 'gcc -O2 -Wall `pkg-config --cflags --libs guile-2.0` -o test-guile' */

#include <libguile.h>
#include <stdio.h>
#include <string.h>

int load;

void* func (void* data)
{

  switch (load)
    {
      case 0:
	scm_c_eval_string("(primitive-load \"test-file.scm\")");
	break;
      default:
	scm_c_eval_string("(load \"./test-file.scm\")");
    }

  return NULL;
}

int main (int argc, char *argv[])
{

  int count;

  if (argc != 2
      || (strcmp (argv[1], "pload") &&
	  strcmp (argv[1], "load")))
    {
      puts ("Usage: test-guile load | pload");
      exit (1);
    }

  if (!strcmp (argv[1], "load"))
    {
      puts("Using load");
      load = 1;
    }
  else
    puts("Using primitive-load");

  for (count = 0; count < 256000; ++count)
    {
      scm_with_guile(func, NULL);

      if (!(count % 100)) {
	printf("%d ", count);
	fflush(stdout);
      }
    }

  puts("");
  return 0;
}





             reply	other threads:[~2014-11-30 23:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-30 23:30 Chris Vine [this message]
2021-05-17 22:25 ` bug#19236: load-compiled procedure leaks memory Taylan Kammer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141130233009.0e596015@bother.homenet \
    --to=chris@cvine.freeserve.co.uk \
    --cc=19236@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).