In regards to episode "Ship in a Bottle" do you think Moriarty figured out he's no longer in physical form, stored in a box, and living in a simulated world? If he did, do you think he's satisfied with that existence? Usually in episodes where someone else is put inside a holodeck without their knowledge they figured it out eventually. With the help of mobile emitter technology or at least a photogenic field generator starfleet would be more capable of giving him a more real existence if they wished.
If the program evolves all the time, Moriarty might not figure out where he is. Moriarty was a sentient creature, Starfleet wouldn't just abandon him in a program.