@@ -105,6 +105,32 @@ function widget:AllowDraw()
105105 return false
106106end
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 ()
119146end
120147
121148function widget :MousePress ()
0 commit comments