-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bram Geron wrote:
> The patch in <parrot.solution1.patch> fixes the problem for me.

I realized that contexts currently initially have a ref_count of 0, if
they're not used as :outer targets for other subs. So in 'normal'
situations, the caller's context's ref_count now drops from 0 to -1 in a
tail call, and since -1 != 0 the caller's context will never be freed,
resulting in a memory leak. Attached <parrot.solution1.updated.patch>
should fix that.

Still, I'm left with a question. How can we DOD a closure? To me it
seems that once a closure exists, it references its context. Often the
context is still left in a register, so the context references the
closure PMC, which in turn references the closure. Because we use
reference counting in these cases, no count ever drops to zero, and they
all live forever.

Sorry for the extra disturbance, thanks for looking at my mail,
- --
Bram Geron | GPG 0xE7B9E65E
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGUKbOvquQbee55l4RAp5wAJ0czwrfQc5Ta/xtMn7FqhSeptq/awCfbNg2
FxMZOHymYqUQCNoyK54pBmo=
=bjro
-----END PGP SIGNATURE-----
Index: src/pmc/sub.pmc
===================================================================
--- src/pmc/sub.pmc	(revision 18597)
+++ src/pmc/sub.pmc	(working copy)
@@ -284,8 +284,9 @@
         if (PObj_get_FLAGS(SELF) & SUB_FLAG_IS_OUTER) {
             /* don't destroy context */
             ccont->vtable = interp->vtables[enum_class_Continuation];
-            context->ref_count++;
         }
+        /* reference counting should work */
+        context->ref_count++;
 
         if (!PMC_IS_NULL(INTERP->current_object)) {
             context->current_object = INTERP->current_object;
@@ -322,7 +323,7 @@
                 PObj_get_FLAGS(ccont) &= ~SUB_FLAG_TAILCALL;
                 context->caller_ctx    = caller_ctx->caller_ctx;
 
-                Parrot_free_context(INTERP, caller_ctx, 1);
+                Parrot_free_context(INTERP, caller_ctx, 0);
             }
         }
 

Reply via email to