<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript" language="JavaScript">
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();
}
if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
origWidth = innerWidth;
origHeight = innerHeight;
onresize = reDo;
}
onerror = null;
</script>
<style type="text/css">
< !-- div.WebHelpPopupMenu {
position: absolute;
left: 0px;
top: 0px;
z-index: 4;
visibility: hidden;
}
p.WebHelpNavBar {
text-align: right;
}
-->
</style>
<script type="text/javascript">
gRootRelPath = "../../..";
gCommonRootRelPath = "../../..";
gTopicId = "9.2.21";
<script type="text/javascript" src="../../../template/scripts/rh.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/common.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/topic.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/topicwidgets.min.js"></script>
<script type="text/javascript" src="../../../whxdata/projectsettings.js"></script>
<link rel="stylesheet" type="text/css" href="../../../template/styles/topic.min.css"/>
<link rel="stylesheet" type="text/css" href="../../../template/Charcoal_Grey/topicheader.css"/>
<meta name="topic-status" content="Draft"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Garbage Collection</title>
<meta name="generator" content="Adobe RoboHelp 2019"/>
<link rel="stylesheet" href="../../../assets/css/default.css" type="text/css"/>
<meta name="rh-authors" content="Mark Alexander"/>
<meta name="topic-comment" content="Reference section for the Garbage Collection functions"/>
<meta name="rh-index-keywords" content=""/>
<meta name="search-keywords" content="Garbage Collection"/>
</head>
<body>
<div class="topic-header rh-hide" id="rh-topic-header" onclick="rh._.goToFullLayout()">
<div class="logo">
</div>
<div class="nav">
<div class="title" title="Garbage Collection">
<span>Garbage Collection</span>
</div>
<div class="gotohome" title="Click here to see this page in full context">
<span>Click here to see this page in full context</span>
</div>
</div>
</div>
<div class="topic-header-shadow rh-hide" id="rh-topic-header-shadow"></div>
<h1>Garbage Collection</h1>
<p>The GameMaker Studio 2 <strong>Garbage Collector</strong> exists because methods can be passed on the stack and left unreferenced, as can structs and a few other things, which in turn would cause a memory leak if they
weren't "cleaned up" in some way. This is where the garbage collector comes in and it will run in the background of the game, collecting anything that's been dereferenced and maintaining an optimal memory usage.</p>
<p class="note"><b>NOTE</b>: Please note that things like surfaces, data structures, buffers and other dynamic resources are <b>not</b> garbage collected and have their own <tt>destroy</tt> functions to clean up the
memory associated with them. As a rule of thumb, if anything you create at runtime has a <tt>destroy</tt> function then it won't be garbage collected and you will have to deal with it yourself in code.</p>
<p>The garbage collection which GameMaker Studio 2 uses is "generational". This means that, in order to reduce the work that must be done every frame, objects are divided into "generations". New objects
are created in generation 0 and they are moved into older generations as they themselves age. The general idea is that objects which hang around for a while don't need to be continuously tested to see if they should be deleted, but can be checked
less frequently (note that "objects" here refers to anything that can be garbage collected and <i>not</i> general object instances as defined in the Asset Browser).</p>
<p>In general you should never need to interact with the GameMaker Studio 2 garbage collection system and normally the results of its operation are not visible but some GML commands are available to get information about
what the collector is doing and to influence its behaviour to a limited degree.</p>
<p class="note"><b>IMPORTANT!</b> Note that on the HTML5 target platform garbage collection is handled by the JavaScript engine and therefore none of the functions listed below will affect its operation and the function <tt>gc_get_stats()</tt> will
returns 0 for all fields.</p>
<p> </p>
<ul class="colour">
<li><a href="gc_enable.htm">gc_enable</a></li>
<li><a href="gc_is_enabled.htm">gc_is_enabled</a></li>
<li><a href="gc_collect.htm">gc_collect</a></li>
<li><a href="gc_get_stats.htm">gc_get_stats</a></li>
</ul>
<p> </p>
<p> </p>
<p> </p>
<div class="footer">
<div class="buttons">
<div class="clear">
<div style="float:left">Back: <a href="../GML_Reference.htm">GML Reference</a></div>
<div style="float:right">Next: <a href="../Variable_Functions/Variable_Functions.htm">Variable Functions</a></div>
</div>
</div>
<h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
</div>
</body></html>