I've tried all these steps before.
My current project incorrectly shows over 25k measures, after the end of the song @ 202. I select all (ctrl+a), and it does select all the empty measures. I select all the empty measures, for all tracks, then delete special (delete hole as well). After delete, still have all the empty measures. I've tried manually deleting any remaining automation nodes, and making sure there aren't any remaining events, in the events viewer.
I'm a longtime programmer, and Cakewalk user, going waaaaay back to 3.1 (LOL)! So, I'm confident that I'm doing everything right. I gave up on this months ago, but thought that a better solution was to have some sort of special functionality to mark the end of the song.