Skip to content

Commit e667855

Browse files
committed
Add beyond-all-reason/BYAR-Chobby@a35b9d3 as it seems like a decent idea.
1 parent 8ed8133 commit e667855

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

LuaMenu/widgets/api_limit_fps.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,32 @@ function widget:AllowDraw()
105105
return false
106106
end
107107

108+
109+
local basememlimit = 200000
110+
local garbagelimit = basememlimit -- in kilobytes, will adjust upwards as needed
111+
local lastGCchecktime = Spring.GetTimer()
112+
113+
local function StrictGarbageCleanup()
114+
if Spring.DiffTimers(Spring.GetTimer(), lastGCchecktime) > 1 then
115+
lastGCchecktime = Spring.GetTimer()
116+
local ramuse = gcinfo()
117+
--Spring.Echo("RAMUSE",ramuse)
118+
if ramuse > garbagelimit then
119+
collectgarbage("collect")
120+
collectgarbage("collect")
121+
local notgarbagemem = gcinfo()
122+
local newgarbagelimit = math.min(1000000, notgarbagemem + basememlimit) -- peak 1 GB
123+
Spring.Echo(string.format("Chobby Using %d MB RAM > %d MB limit, performing garbage collection to %d MB and adjusting limit to %d MB",
124+
math.floor(ramuse/1000),
125+
math.floor(garbagelimit/1000),
126+
math.floor(notgarbagemem/1000),
127+
math.floor(newgarbagelimit/1000) )
128+
)
129+
garbagelimit = newgarbagelimit
130+
end
131+
end
132+
end
133+
108134
--------------------------------------------------------------------------------
109135
--------------------------------------------------------------------------------
110136
-- Force redraw on input or screen resize
@@ -116,6 +142,7 @@ function widget:Update()
116142
fastRedraw = true
117143
end
118144
oldX, oldY = x, y
145+
StrictGarbageCleanup()
119146
end
120147

121148
function widget:MousePress()

0 commit comments

Comments
 (0)