The GameMaker Studio 2 Garbage Collector 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.
NOTE: Please note that things like surfaces, data structures, buffers and other dynamic resources are not garbage collected and have their own destroy functions to clean up the memory associated with them. As a rule of thumb, if anything you create at runtime has a destroy function then it won't be garbage collected and you will have to deal with it yourself in code.
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 not general object instances as defined in the Asset Browser).
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.
IMPORTANT! 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 gc_get_stats() will returns 0 for all fields.