@@ -27,8 +27,9 @@ MemoryGarbageCollector = {
2727local EM = EVENT_MANAGER
2828local MGC = MemoryGarbageCollector
2929
30- local maxMemoryUsage = MGC .maxMemoryUsage
31- local chatColor = MGC .color
30+ local Config = MGC .config
31+ local MaxMemoryUsage = MGC .maxMemoryUsage
32+ local ChatColor = MGC .color
3233
3334local DEFAULT_SAVED_VARS = {
3435 autoClear = true ,
@@ -58,8 +59,6 @@ function MGC.Initialize()
5859end
5960
6061function MGC .InitMenu ()
61- local config = MGC .config
62-
6362 local LAM = LibAddonMenu2
6463 local panelName = MGC .name .. " _LAM"
6564
@@ -85,10 +84,10 @@ function MGC.InitMenu()
8584 name = GFS (SI_MGC_AUTO_CLEAR ),
8685 tooltip = GFS (SI_MGC_AUTO_CLEAR_TOOLTIP ),
8786 getFunc = function ()
88- return config .autoClear
87+ return Config .autoClear
8988 end ,
9089 setFunc = function (v )
91- config .autoClear = v
90+ Config .autoClear = v
9291 MGC .refreshSettings ()
9392 end ,
9493 default = DEFAULT_SAVED_VARS .autoClear ,
@@ -101,13 +100,13 @@ function MGC.InitMenu()
101100 max = 60 ,
102101 decimals = 0 ,
103102 disabled = function ()
104- return not config .autoClear
103+ return not Config .autoClear
105104 end ,
106105 getFunc = function ()
107- return config .refreshRate
106+ return Config .refreshRate
108107 end ,
109108 setFunc = function (v )
110- config .refreshRate = v
109+ Config .refreshRate = v
111110 MGC .refreshSettings ()
112111 end ,
113112 default = DEFAULT_SAVED_VARS .refreshRate ,
@@ -117,13 +116,13 @@ function MGC.InitMenu()
117116 name = GFS (SI_MGC_COMPARISON_METHOD ),
118117 tooltip = GFS (SI_MGC_COMPARISON_METHOD_TOOLTIP ),
119118 disabled = function ()
120- return not config .autoClear
119+ return not Config .autoClear
121120 end ,
122121 getFunc = function ()
123- return config .comparisonMethod
122+ return Config .comparisonMethod
124123 end ,
125124 setFunc = function (v )
126- config .comparisonMethod = v
125+ Config .comparisonMethod = v
127126 MGC .refreshSettings ()
128127 end ,
129128 choicesValues = { 1 , 2 },
@@ -139,13 +138,13 @@ function MGC.InitMenu()
139138 step = 5 ,
140139 decimals = 0 ,
141140 disabled = function ()
142- return not (config .autoClear and config .comparisonMethod == 1 )
141+ return not (Config .autoClear and Config .comparisonMethod == 1 )
143142 end ,
144143 getFunc = function ()
145- return config .overflowRelative
144+ return Config .overflowRelative
146145 end ,
147146 setFunc = function (v )
148- config .overflowRelative = v
147+ Config .overflowRelative = v
149148 MGC .refreshSettings ()
150149 end ,
151150 default = DEFAULT_SAVED_VARS .overflowRelative ,
@@ -159,13 +158,13 @@ function MGC.InitMenu()
159158 step = 25 ,
160159 decimals = 0 ,
161160 disabled = function ()
162- return not (config .autoClear and config .comparisonMethod == 2 )
161+ return not (Config .autoClear and Config .comparisonMethod == 2 )
163162 end ,
164163 getFunc = function ()
165- return config .overflowAbsolute
164+ return Config .overflowAbsolute
166165 end ,
167166 setFunc = function (v )
168- config .overflowAbsolute = v
167+ Config .overflowAbsolute = v
169168 MGC .refreshSettings ()
170169 end ,
171170 default = DEFAULT_SAVED_VARS .overflowAbsolute ,
@@ -175,13 +174,13 @@ function MGC.InitMenu()
175174 name = GetString (SI_SETTINGSYSTEMPANEL6 ),
176175 tooltip = GetString (SI_MGC_SHOW_DEBUG_MESSAGES ),
177176 disabled = function ()
178- return not config .autoClear
177+ return not Config .autoClear
179178 end ,
180179 getFunc = function ()
181- return config .showDebugMessages
180+ return Config .showDebugMessages
182181 end ,
183182 setFunc = function (v )
184- config .showDebugMessages = v
183+ Config .showDebugMessages = v
185184 MGC .refreshSettings ()
186185 end ,
187186 default = DEFAULT_SAVED_VARS .showDebugMessages ,
@@ -201,31 +200,35 @@ function MGC.setRefreshTimer()
201200 local eventName = MGC .name .. " _Auto"
202201 EVENT_MANAGER :UnregisterForUpdate (eventName )
203202
204- if MGC . config .autoClear == true then
205- local refreshSeconds = MGC . config .refreshRate * 60 * 1000 -- min to seconds
203+ if Config .autoClear == true then
204+ local refreshSeconds = Config .refreshRate * 60 * 1000 -- min to seconds
206205 EVENT_MANAGER :RegisterForUpdate (eventName , refreshSeconds , function ()
207206 MGC .checkGarbage ()
208207 end )
209208 end
210209end
211210
212211function MGC .calcMaxMemory (memory )
212+ if not Config .autoClear then
213+ return
214+ end
215+
213216 if not memory then
214217 memory = MGC .currentMemory ()
215218 end
216219
217220 local max = 1024
218- if MGC . config .comparisonMethod == 1 then
219- max = memory * (1 + MGC . config .overflowRelative / 100 )
221+ if Config .comparisonMethod == 1 then
222+ max = memory * (1 + Config .overflowRelative / 100 )
220223 else
221- max = memory + MGC . config .overflowAbsolute
224+ max = memory + Config .overflowAbsolute
222225 end
223226
224227 -- Round to 5 MB
225228 max = math.ceil (max / 5 ) * 5
226229
227230 MGC .sendDebugMessage (GFS (SI_MGC_MEMORY_INIT_MAX , max ))
228- maxMemoryUsage = max
231+ MaxMemoryUsage = max
229232end
230233
231234function MGC .currentMemory ()
@@ -237,7 +240,7 @@ function MGC.checkGarbage()
237240 return
238241 end
239242
240- local limit = maxMemoryUsage or 1024 ;
243+ local limit = MaxMemoryUsage or 1024 ;
241244 local current = MGC .currentMemory ()
242245
243246 -- Check currently used memory for overflow limit.
@@ -263,17 +266,17 @@ function MGC.chatMessage(message)
263266 MGC .chat = LibChatMessage (MGC .shortName , MGC .shortName )
264267 end
265268
266- local formatted = SF (" |c%s[%s]|r %s" , chatColor .grey , GetTimeString (), message )
267- MGC .chat :SetTagColor (chatColor .main ):Printf (formatted )
269+ local formatted = SF (" |c%s[%s]|r %s" , ChatColor .grey , GetTimeString (), message )
270+ MGC .chat :SetTagColor (ChatColor .main ):Printf (formatted )
268271 else
269- local formatted = SF (" %s |c%s[%s]|r %s" , MGC .prefix , chatColor .grey , GetTimeString (), message )
272+ local formatted = SF (" %s |c%s[%s]|r %s" , MGC .prefix , ChatColor .grey , GetTimeString (), message )
270273 CHAT_SYSTEM :AddMessage (formatted )
271274 end
272275end
273276
274277-- Send debug message to game chat
275278function MGC .sendDebugMessage (message )
276- if MGC . config .showDebugMessages then
279+ if Config .showDebugMessages then
277280 MGC .chatMessage (message )
278281 end
279282end
0 commit comments