unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Whitlock, Bradley D" <bradley.d.whitlock@lmco.com>
To: "guile-user@gnu.org" <guile-user@gnu.org>
Subject: Guile 1.8 Garbage Collection Question
Date: Tue, 25 Oct 2011 20:34:23 +0000	[thread overview]
Message-ID: <1B716C7666FD684A9FDF0FBD5EE5E0A0156F8529@HDXDSP11.us.lmco.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2080 bytes --]

I have built Guile 1.8.8.2 on MinGW.

I have wrapped some gtkwave code with Guile and have a memory issue. The following code apparently never frees 's', but I am not sure why.

SCM_DEFINE (libguile_fst_writer_emit_value, "libguile-fst-writer-emit-value",
                    3,0,0,
                    (SCM scm_ctx, SCM scm_fsthandle, SCM scm_val),
                    "Write a change on fstHandle")
{
  // Storage for temporary string
  char* s = NULL;
  scm_dynwind_begin (0);
  scm_dynwind_unwind_handler (free, s, SCM_F_WIND_EXPLICITLY);

  s = scm_to_locale_string (scm_val);

  fstWriterEmitValueChange(SCM_TO_CTX (scm_ctx),
                                                   SCM_TO_FSTHANDLE (scm_fsthandle),
                                                   s_buf);

  scm_dynwind_end();

  return SCM_UNSPECIFIED;
}

The code is called from Scheme land in the following loop:

(let loop ((n 0))
  (if (eq? n 10000000) #t
      (begin

                ;; Emit some changes on the signal
                (fst-emit-value ctx s (number->string (modulo n 2)))
                (fst-emit-value ctx s1 (number->string (modulo (1+ n) 2)))
                (fst-emit-time-change ctx n)

                (loop (1+ n))
                )))

It seems to me that the garbage collector never gets a chance to run, so how do I make sure that the gc gets a turn?

If I define my function like the following, the leak disappears, but it's a less desirable solution:

SCM_DEFINE (libguile_fst_writer_emit_value, "libguile-fst-writer-emit-value",
                    3,0,0,
                    (SCM scm_ctx, SCM scm_fsthandle, SCM scm_val),
                    "Write a change on fstHandle")
{
  // Storage for temporary string
  char s_buf [1024];
  scm_to_locale_stringbuf (scm_val, s_buf, 1024);
  s = scm_to_locale_string (scm_val);

  fstWriterEmitValueChange(SCM_TO_CTX (scm_ctx),
                                                   SCM_TO_FSTHANDLE (scm_fsthandle),
                                                   s_buf);

  return SCM_UNSPECIFIED;
}

Any suggestion?

Thanks,
Brad

[-- Attachment #2: Type: text/html, Size: 10915 bytes --]

             reply	other threads:[~2011-10-25 20:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-25 20:34 Whitlock, Bradley D [this message]
2011-10-26  5:15 ` Guile 1.8 Garbage Collection Question Cedric Cellier
2011-10-26  8:39 ` Andy Wingo
2011-10-26 16:07   ` EXTERNAL: " Whitlock, Bradley D
2011-10-26 16:28     ` rixed
2011-10-26 16:30 ` rixed
  -- strict thread matches above, loose matches on Subject: below --
2011-10-25 20:36 Whitlock, Bradley D

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=1B716C7666FD684A9FDF0FBD5EE5E0A0156F8529@HDXDSP11.us.lmco.com \
    --to=bradley.d.whitlock@lmco.com \
    --cc=guile-user@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).