unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Guile 1.8 Garbage Collection Question
@ 2011-10-25 20:34 Whitlock, Bradley D
  2011-10-26  5:15 ` Cedric Cellier
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Whitlock, Bradley D @ 2011-10-25 20:34 UTC (permalink / raw)
  To: guile-user@gnu.org

[-- 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 --]

^ permalink raw reply	[flat|nested] 7+ messages in thread
* RE: Guile 1.8 Garbage Collection Question
@ 2011-10-25 20:36 Whitlock, Bradley D
  0 siblings, 0 replies; 7+ messages in thread
From: Whitlock, Bradley D @ 2011-10-25 20:36 UTC (permalink / raw)
  To: guile-user@gnu.org

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

I had a copy-paste error in the second function listing, it should be this:

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);

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

  return SCM_UNSPECIFIED;
}

-Brad

From: Whitlock, Bradley D
Sent: Tuesday, October 25, 2011 2:34 PM
To: 'guile-user@gnu.org'
Subject: Guile 1.8 Garbage Collection Question

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: 14055 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-10-26 16:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-25 20:34 Guile 1.8 Garbage Collection Question Whitlock, Bradley D
2011-10-26  5:15 ` 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

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).