# Is it possible to remove length, counter, dim, etc that have been declared?

Let's see the following screenshot taken from an answer of Efficient ways to anonymize a document and the given comment.

Is it possible to remove length, counter, dim, etc, that have been declared in a macro, before leaving the macro?

-
– Andrey Vihrov Feb 22 '12 at 12:51

No, it's not possible: \newlength allocates a register and this allocation is permanent. If you do the \newlength inside a group, you'll lose the register name at group end, but the register will not be reusable.

Actually it might be possible: define a macro \startlocalallocations that modifies \newlength and \newcounter in such a way that allocations from that point on are stored in a convenient macro, say \allocationsmade, and then define \removelocalallocations that uses \allocationsmade to restore the status as it was before the starting command.

While feasible (at least in principle), this is completely useless. Registers should be allocated outside macro definitions: they can be set and used as many times as one wants. So the correct way to define \blind is

\newlength{\sowide}
\newlength{\sohigh}
\def\blind#1{%
...
\settowidth{\sowide}{#1}%
\settoheight{\sohigh}{H}%
...}


and all will work. There's no need to allocate a temporary variable.

Note: the package etex allows for local allocations. But this is useful in contexts very different from this one: one can think to the allocation of a block of registers for some particular use, when they are not called by name, but by numbers. See the implementation of the float mechanism for a slightly different example in which a block of registers is allocated and they are called \bx@A, \bx@B, ..., \bx@R in order that the next free register can be used by knowing the number of the last one used.

-