try to manage lua memory leak prevention in a way thats safer from re-entrancy during finalization thread
This commit is contained in:
parent
6982df8035
commit
e12c711a0e
|
@ -159,6 +159,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
EventsLibrary.CurrentThread = script;
|
||||
_currThread = script;
|
||||
var execResult = script.Resume(0);
|
||||
|
||||
_lua.RunScheduledDisposes();
|
||||
//not sure how this is going to work out, so do this too
|
||||
script.RunScheduledDisposes();
|
||||
|
||||
_currThread = null;
|
||||
var result = new ResumeResult();
|
||||
if (execResult == 0)
|
||||
|
|
|
@ -959,6 +959,26 @@ namespace LuaInterface
|
|||
|
||||
#endregion
|
||||
|
||||
List<int> scheduledDisposes = new List<int>();
|
||||
|
||||
internal void ScheduleDispose(int reference)
|
||||
{
|
||||
//TODO - theres a race condition here, see comment elsewhere
|
||||
lock (scheduledDisposes)
|
||||
scheduledDisposes.Add(reference);
|
||||
}
|
||||
|
||||
public void RunScheduledDisposes()
|
||||
{
|
||||
//TODO - theres a race condition here, in case GC happens during this method
|
||||
lock (scheduledDisposes)
|
||||
{
|
||||
foreach (var item in scheduledDisposes)
|
||||
dispose(item);
|
||||
scheduledDisposes.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
internal void dispose(int reference)
|
||||
{
|
||||
if (luaState != IntPtr.Zero) //Fix submitted by Qingrui Li
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace LuaInterface
|
|||
~LuaBase()
|
||||
{
|
||||
//Dispose(false);
|
||||
Dispose(true); //zero 28-feb-2014 - fix memory leak?
|
||||
Dispose(true); //zero 28-feb-2015 - fix memory leak?
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
@ -31,8 +31,8 @@ namespace LuaInterface
|
|||
{
|
||||
if (disposeManagedResources)
|
||||
{
|
||||
if (_Reference != 0)
|
||||
_Interpreter.dispose(_Reference);
|
||||
if (_Reference != 0 && _Interpreter != null)
|
||||
_Interpreter.ScheduleDispose(_Reference);
|
||||
}
|
||||
_Interpreter = null;
|
||||
_Disposed = true;
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue