I was wondering how does TeX manage counters. In particular, assuming I define a new counter in TeX by \newcount\mycounter and at some point I don't need it anymore, can I delete it and free the associated registry?

This may be useful when one needs to use a sequence of counters \c1, \c2, ..., \c<n> where n may become large, and at some point there is no need for some of the counters in the sequence (say, up to some index).

  • 3
    You can free it without worrying about the name, but the problem is that the standard allocation system (from plain TeX and inherited by LaTeX2e and ConTeXt) is not really designed for this. You could look at the e-TeX mechanism, but that is still more about freeing when TeX groups end. One could write a system to allow freeing, but with e-TeX providing 32k registers, I'm not sure of the need!
    – Joseph Wright
    Commented May 17, 2012 at 13:42

1 Answer 1


If the usage of the n counters is specific for some task you can do the computations in a group and assign them whatever register you want:

<the computations where the total is stored in \mycounta>

The local equivalence of \mycounta to \count11 will be forgotten at the end of the group as will be their values. As long as you don't use any "external" counter in your computation, you'll be sure that no conflict will arise.

Freeing counters would require a rather complex rewriting of the allocation macros; this is not very important with e-TeX that provides 32768 registers of each type.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .