staticdata: fix unreferenced data assertion (#39246)
Need to sequence operations correctly here. We need to first finish
marking referenced data before we start deleting unreferenced data. This
otherwise can lead to an assertion failure in some situations.
Refs #37650