Q:

How memoir prints the titles of the content pages?

On the question How to dynamically calculate the height of an empty list of things?, I learned I am required to now how my class calculates its contents page title in order to make the answer to works. I tried \large\contentsname\vskip\baselineskip\vskip\afterchapskip, but it was not enough, as the List of Tables is empty (there are no tables) and it should not be displayed:
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6400)
entering extended mode
(test3.tex
LaTeX2e <2017-04-15>
Babel <3.12> and hyphenation patterns for 76 language(s) loaded.
(D:\User\Documents\latex\texmfs\install\tex\latex\memoir\memoir.cls
Document Class: memoir 2016/05/16 v3.7f configurable book, report, article docu
ment class
(D:\User\Documents\latex\texmfs\install\tex\generic\oberdiek\ifpdf.sty)
(D:\User\Documents\latex\texmfs\install\tex\latex\ifetex\ifetex.sty
(D:\User\Documents\latex\texmfs\install\tex\plain\ifetex\ifetex.tex))
(D:\User\Documents\latex\texmfs\install\tex\generic\ifxetex\ifxetex.sty)
(D:\User\Documents\latex\texmfs\install\tex\generic\oberdiek\ifluatex.sty)
(D:\User\Documents\latex\texmfs\install\tex\latex\memoir\mem12.clo)) (test3.aux
) (test3.toc) (test3.lof)
The height of the list 'List of Figures' is '131.77776pt' from '67.84pt'
(test3.lot)
The height of the list 'List of Tables' is '117.27776pt' from '67.84pt'
[1{D:/User/Documents/latex/texmfs/data/pdftex/config/pdftex.map}] [2] [3]
(test3.aux) )<D:/User/Documents/latex/texmfs/install/fonts/type1/public/amsfont
s/cm/cmbx12.pfb><D:/User/Documents/latex/texmfs/install/fonts/type1/public/amsf
onts/cm/cmr12.pfb>
Output written on test3.pdf (3 pages, 23659 bytes).
Transcript written on test3.log.

How can I set \boxBforwhenlistisnotempty for memoir titles page?
\documentclass[12pt,a4paper]{memoir}

\newbox\boxAforwhenlistisnotempty
\newbox\boxBforwhenlistisnotempty

\newcommand{\whenlistisnotempty}[2]{%
  \setbox\boxAforwhenlistisnotempty\vbox{#2}%
  \setbox\boxBforwhenlistisnotempty\vbox{%
    \large\contentsname\vskip\baselineskip\vskip\afterchapskip%
  }%
  \typeout{The height of the list '#1'
      is '\the\ht\boxAforwhenlistisnotempty'
      from '\the\ht\boxBforwhenlistisnotempty'}%
  \ifdim\ht\boxAforwhenlistisnotempty>\ht\boxBforwhenlistisnotempty%
    \unvbox\boxAforwhenlistisnotempty%
  \fi%
}

\begin{document}
\tableofcontents

\whenlistisnotempty{\listfigurename}{
\listoffigures
}

\whenlistisnotempty{\listtablename}{
\listoftables
}

\chapter{First section}

\begin{figure}
    \centering
    Figure
    \caption{Caption}
\end{figure}

\end{document}

References

How to stop \newsavebox giving me bad boxes warnings or how to use better names with \setbox?

A:

Not an answer but this might help.
If you call \listoftables then the .lot file is created. A \chapter command will add 
\addvspace{10pt}

to the file and a table caption will add something like
\contentsline{table}{\numberline}{1.1}{\ignorespaces A table}}{3}%

to the file.
If there are no tables then the .lot file will just contain the \addvspace{10pt}
Having looked at your previous questions (and the answers) on this topic I have, with the assistance of ... (https://tex.stackechange.com/questions.com/questions/51575/How-to-dynamically-calculate-the-height-of-an-empty-list-of-things? come up with a solution to your problem of not showing a List of Tables when there are no tables.
% tocprob21.tex  SE 515811  No LoT if no tables?

\documentclass{memoir}
\usepackage{comment}

\newsavebox{\testbox}
\newsavebox{\testboxB}
\def\wheninteresting#1{%
\savebox{\testbox}{\vbox{#1}}%
\savebox{\testboxB}{\vbox{\chapter*{\contentsname}}}
\ifdim\ht\testbox>\ht\testboxB
\usebox{\testbox}
\fi}

\begin{document}

\wheninteresting{
\listoftables
}

\chapter{One}

Some text

\begin{figure}
\centering
FIGURE
\caption{A figure}
\end{figure}

\begin{comment}
\begin{table}
\centering
TABLE
\caption{A table}
\end{table}
\end{comment}

\end{document}

