[CM] Freeing up s7 instances & memory

Christos Vagias chris.actondev at gmail.com
Sat Sep 12 12:26:39 PDT 2020


Thanks a lot Bil! That was quick.

I just went on testing it and sadly the scenario I had described initially
sees no improvement at all.
(and yes, I'm calling s7_free instead of free heh)

If it's of any help, here's another scenario where the behavior is kind of
weird
(it was like this even before this patch actually)

    for (int i = 0; i < 10; i++) {
        s7_scheme *sc = s7_init();
        aod::s7::bind_all(sc);

        for (int j = 0; j < 10; j++) {
            // 10 times creating a ~10mb string
            s7_eval_c_string(sc, //
                             "(define x ((aod.c.foreign 'new-char[])
10000000))" // 10 mb
                            );
        }
        s7_eval_c_string(sc, "(gc)");
        s7_eval_c_string(sc, "(gc)");

        s7_free(sc);
    }

So, 10 loops of 10 times ~10mb.
After this first inner loop (10 times 10mb char*),
Before the first (gc) call I notice the memory usage jump from 18mb (init)
to 113mb ( + ~100mb as expected)
- 1st call to (gc) has no effect
- After the 2nd (gc) call, I see the memory usage dropping to 28mb

Then, the s7_free has no effect at all.
Then, in any subsequent loop (i=1,2...) the (gc) call has no immediate
effect!
The memory however doesn't increase as much in each loop, guess certain
memory is being
reused.

Now, if I skip the (gc) calls, the memory once more tends to grow 100mb per
outer loop.

If I leave one (gc) call, I'm back to where in the first outer loop ~100mb
are free and then
in subsequent loops the memory doesn't increase as much.

:::::::
Hope this isn't too confusing.

What seems to happen:
2 calls are needed to the (gc) to have any effect. In my scenario where I
call only once the (gc),
the thing is that s7_free also calls once g_gc(sc, sc->nil);

And, again, note that in my original snippet (where I only create 1 big
object), s7_free seems to have
no effect (the (gc) calls neither)


Hope this is kind of useful.

On Sat, 12 Sep 2020 at 11:46, <bil at ccrma.stanford.edu> wrote:

> I think s7_free is usable now.  I also have a valgrind
> suppressions file for it which I could include in the
> s7 tarball if it seems useful.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20200912/a5985661/attachment.html>


More information about the Cmdist mailing list