mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-01 21:48:28 -04:00
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:
parent
1484a12f4b
commit
7fdc9fef12
@ -393,9 +393,15 @@ void lua_scripts::run(void) {
|
|||||||
const uint32_t runEnd = AP_HAL::micros();
|
const uint32_t runEnd = AP_HAL::micros();
|
||||||
const int endMem = lua_gc(L, LUA_GCCOUNT, 0) * 1024 + lua_gc(L, LUA_GCCOUNTB, 0);
|
const int endMem = lua_gc(L, LUA_GCCOUNT, 0) * 1024 + lua_gc(L, LUA_GCCOUNTB, 0);
|
||||||
if (_debug_level > 1) {
|
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 {
|
} else {
|
||||||
gcs().send_text(MAV_SEVERITY_DEBUG, "Lua: No scripts to run");
|
gcs().send_text(MAV_SEVERITY_DEBUG, "Lua: No scripts to run");
|
||||||
hal.scheduler->delay(10000);
|
hal.scheduler->delay(10000);
|
||||||
|
Loading…
Reference in New Issue
Block a user