AP_Scripting: Garbage collect after each run of a script

For some reason this resolves a memory leak in a tight loop of file
open, close. This also extends the memory debug printing to be a bit
more useful.
This commit is contained in:
Michael du Breuil 2019-08-26 17:25:23 -07:00 committed by Andrew Tridgell
parent 1484a12f4b
commit 7fdc9fef12

View File

@ -393,9 +393,15 @@ void lua_scripts::run(void) {
const uint32_t runEnd = AP_HAL::micros();
const int endMem = lua_gc(L, LUA_GCCOUNT, 0) * 1024 + lua_gc(L, LUA_GCCOUNTB, 0);
if (_debug_level > 1) {
gcs().send_text(MAV_SEVERITY_DEBUG, "Lua: Time: %u Mem: %d", (unsigned int)(runEnd - loadEnd), (int)(endMem - startMem));
gcs().send_text(MAV_SEVERITY_DEBUG, "Lua: Time: %u Mem: %d + %d",
(unsigned int)(runEnd - loadEnd),
(int)endMem,
(int)(endMem - startMem));
}
// garbage collect after each script, this shouldn't matter, but seems to resolve a memory leak
lua_gc(L, LUA_GCCOLLECT, 0);
} else {
gcs().send_text(MAV_SEVERITY_DEBUG, "Lua: No scripts to run");
hal.scheduler->delay(10000);