On 10/22/07, Melchior FRANZ <[EMAIL PROTECTED]> wrote:
>
> That's not quite right. The GC might be OK, but it seems
> that it isn't invoked on cmdarg() nodes. I'll discuss that
> with Andy once he shows up on IRC again.

Don't know if Melchior and Andy have arrived at anything while I was
away, but here is what I found.

In FGNasalListener::call the arguments are set up for the call.
arg[0] = _nas->propNodeGhost(which);
arg[1] = _nas->propNodeGhost(_node);

These end up in naNewGhost, and finally in naNew where *the new object
gets stored in the  temps list for the context*, prohibiting garbage
collection. Note that in FGNasalSys::call a new context is created for
executing the call, so while the comment for naTempSave says 'the
object is automatically released when the context next runs native
bytecode" this actually never happens until the context is finally
freed. So new ghosts are created over and over again. Attached patches
to sg and fg seem to fix it if tested with Melchior's gctest.nas.
On second thought, a better fix would be to actually create the ghosts
in the context that will be executed. But I am not changing it now,
it's 5AM ;)

I am not familiar with the nasal system, so this might be completely wrong.
Also, I am not sure this has anything to do with the stuttering. But
it seems to be a memory leak, though.

-- 
Greets,
Csaba/Jester
Index: simgear/nasal/misc.c
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/nasal/misc.c,v
retrieving revision 1.9
diff -u -r1.9 misc.c
--- simgear/nasal/misc.c        30 May 2007 22:49:41 -0000      1.9
+++ simgear/nasal/misc.c        23 Oct 2007 02:46:24 -0000
@@ -26,6 +26,11 @@
     c->temps[c->ntemps++] = PTR(r).obj;
 }
 
+void naFreeTemps(naContext c)
+{
+    c->ntemps = 0;
+}
+
 naRef naObj(int type, struct naObj* o)
 {
     naRef r;
Index: simgear/nasal/nasal.h
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/nasal/nasal.h,v
retrieving revision 1.10
diff -u -r1.10 nasal.h
--- simgear/nasal/nasal.h       30 May 2007 22:49:41 -0000      1.10
+++ simgear/nasal/nasal.h       23 Oct 2007 02:46:25 -0000
@@ -46,6 +46,7 @@
 // context next runs native bytecode.  Useful for saving off C-space
 // temporaries to protect them before passing back into a naCall.
 void naTempSave(naContext c, naRef r);
+void naFreeTemps(naContext c);
 
 // Parse a buffer in memory into a code object.  The srcFile parameter
 // is a Nasal string representing the "file" from which the code is
Index: src/Scripting/NasalSys.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Scripting/NasalSys.cxx,v
retrieving revision 1.95
diff -u -r1.95 NasalSys.cxx
--- src/Scripting/NasalSys.cxx  18 Oct 2007 11:43:38 -0000      1.95
+++ src/Scripting/NasalSys.cxx  23 Oct 2007 02:47:28 -0000
@@ -90,6 +90,7 @@
     _callCount--;
     if(_callCount) naModLock();
     naFreeContext(ctx);
+    naFreeTemps(_context);
     return result;
 }
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to