Fix SI-7130: Memory leaked caused by Statistics

As described in the ticket, we were leaking memory by holding reference
to Global through by-name argument that was captured by an instance of
a class stored in global HashMap `qs`.

The fix is simple: do not register quantities in HashMap unless statistics
is enabled. This way, if Statistics is disabled we do not store any
references.

We still leak memory in case of statistics being enabled.