Collectgarbage: Difference between revisions

From GiderosMobile
No edit summary
mNo edit summary
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
'''Available since:''' Gideros 2011.6<br/>
'''Available since:''' Gideros 2011.6<br/>
'''Class:''' [[(global)]]<br/>
=== Description ===
=== Description ===
<translate>This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt:  
This function is a generic interface to the garbage collector.
<ul>
<syntaxhighlight lang="lua">
<li>"stop": stops the garbage collector. </li>
collectgarbage(opt,arg)
<li>"restart": restarts the garbage collector. </li>
</syntaxhighlight>
<li>"collect": performs a full garbage-collection cycle. </li>
 
<li>"count": returns the total memory in use by Lua (in Kbytes). </li>
It performs different functions according to its first argument, opt:
<li>"step": performs a garbage-collection step. The step "size" is controlled by arg (larger values mean more steps) in a non-specified way. If you want to control the step size you must experimentally tune the value of arg. Returns true if the step finished a collection cycle. </li>
*"stop": stops the garbage collector
<li>"setpause": sets arg as the new value for the pause of the collector. Returns the previous value for pause. </li>
*"restart": restarts the garbage collector
<li>"setstepmul": sets arg as the new value for the step multiplier of the collector. Returns the previous value for step.</li>
*"collect": performs a full garbage-collection cycle
</ul></translate>
*"count": returns the total memory in use by Lua (in Kbytes)
<source lang="lua">
*"step": performs a garbage-collection step. The step "size" is controlled by arg (larger values mean more steps) in a non-specified way. If you want to control the step size you must experimentally tune the value of arg. Returns true if the step finished a collection cycle
collectgarbage(opt,arg)
*"setpause": sets arg as the new value for the pause of the collector. Returns the previous value for pause
</source>
*"setstepmul": sets arg as the new value for the step multiplier of the collector. Returns the previous value for step
 
=== Parameters ===
=== Parameters ===
'''opt''': (string) <translate>command for garbage collector mechanism</translate> <br/>
'''opt''': (string) command for garbage collector mechanism<br/>
'''arg''': (varies) <translate>additional parameters for command</translate> '''optional'''<br/>
'''arg''': (varies) additional parameters for command '''optional'''<br/>
 
=== Example ===
'''Takes over automatic garbage collection, do it in small steps. Increase/decrease the amount depending on your game'''
<syntaxhighlight lang="lua">
collectgarbage("setstepmul", 1000)
collectgarbage()
</syntaxhighlight>
 
{{(global)}}

Latest revision as of 15:47, 4 May 2025

Available since: Gideros 2011.6
Class: (global)

Description

This function is a generic interface to the garbage collector.

collectgarbage(opt,arg)

It performs different functions according to its first argument, opt:

  • "stop": stops the garbage collector
  • "restart": restarts the garbage collector
  • "collect": performs a full garbage-collection cycle
  • "count": returns the total memory in use by Lua (in Kbytes)
  • "step": performs a garbage-collection step. The step "size" is controlled by arg (larger values mean more steps) in a non-specified way. If you want to control the step size you must experimentally tune the value of arg. Returns true if the step finished a collection cycle
  • "setpause": sets arg as the new value for the pause of the collector. Returns the previous value for pause
  • "setstepmul": sets arg as the new value for the step multiplier of the collector. Returns the previous value for step

Parameters

opt: (string) command for garbage collector mechanism
arg: (varies) additional parameters for command optional

Example

Takes over automatic garbage collection, do it in small steps. Increase/decrease the amount depending on your game

collectgarbage("setstepmul", 1000)
collectgarbage()