I highly encourage you to read entirely the mozilla documentation that you linked:
Allocate the memory you need,
use the allocated memory (read, write) and
release the allocated memory when it is not needed anymore.
The first and second parts are explicit in all languages. The last part is explicit in low-level languages, but is mostly implicit in high-level languages like JavaScript.
Garbage collection by references:
This is the most naive garbage collection algorithm. This algorithm reduces the definition of "an object is not needed anymore" to "an object has no other object referencing to it". An object is considered garbage collectable if there is zero reference pointing at this object. There is a limitation when it comes to cycles.
Mark-and-sweep algorithm:
This algorithm reduces the definition of "an object is not needed anymore" to "an object is unreachable". This algorithm assumes the knowledge of a set of objects called roots (In JavaScript, the root is the global object). Periodically, the garbage-collector will start from these roots, find all objects that are referenced from these roots, then all objects referenced from these, etc. Starting from the roots, the garbage collector will thus find all reachable objects and collect all non-reachable objects.
Conclusion: If your object is not reachable from anywhere (in your case when you exit the function), it will be garbage collected. This is not something that you have to worry about in higher level languages.
Edit: Thanks Roland Starke for pointing out that you can read the specifications of how the garbage collector will handle the XMLHttpRequest here.