Fix memory leak introduced when we stopped using _context for script
invocations, but left it in place for miscellaneous allocation work. Contexts cache allocated objects in a temps vector and only clear it out when they are used. Also, fix a type warning while I'm in there.
This commit is contained in:
parent
44a1dbf090
commit
6432d714cc
1 changed files with 14 additions and 1 deletions
|
@ -674,6 +674,19 @@ void FGNasalSys::update(double)
|
||||||
for(it = _dead_listener.begin(); it != end; ++it) delete *it;
|
for(it = _dead_listener.begin(); it != end; ++it) delete *it;
|
||||||
_dead_listener.clear();
|
_dead_listener.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The global context is a legacy thing. We use dynamically
|
||||||
|
// created contexts for naCall() now, so that we can call them
|
||||||
|
// recursively. But there are still spots that want to use it for
|
||||||
|
// naNew*() calls, which end up leaking memory because the context
|
||||||
|
// only clears out its temporary vector when it's *used*. So just
|
||||||
|
// junk it and fetch a new/reinitialized one every frame. This is
|
||||||
|
// clumsy: the right solution would use the dynamic context in all
|
||||||
|
// cases and eliminate _context entirely. But that's more work,
|
||||||
|
// and this works fine (yes, they say "New" and "Free", but
|
||||||
|
// they're very fast, just trust me). -Andy
|
||||||
|
naFreeContext(_context);
|
||||||
|
_context = naNewContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loads the scripts found under /nasal in the global tree
|
// Loads the scripts found under /nasal in the global tree
|
||||||
|
@ -932,7 +945,7 @@ naRef FGNasalSys::setListener(naContext c, int argc, naRef* args)
|
||||||
return naNil();
|
return naNil();
|
||||||
}
|
}
|
||||||
|
|
||||||
int type = argc > 3 && naIsNum(args[3]) ? args[3].num : 1;
|
int type = argc > 3 && naIsNum(args[3]) ? (int)args[3].num : 1;
|
||||||
FGNasalListener *nl = new FGNasalListener(node, code, this,
|
FGNasalListener *nl = new FGNasalListener(node, code, this,
|
||||||
gcSave(code), _listenerId, type);
|
gcSave(code), _listenerId, type);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue