Surely there must be something more elegant than using the volatile keyword and a manually written loop. Honestly, the aforementioned links don't do a very good job of explaining why the volatile keyword prevents optimization. Moreover, how can the compiler possibly know what is going to happen at run-time? If I try to reset pointers to zero in a destructor after destroying an object, will that be optimized away? That makes no sense to me, but the compiler could determine that operation is pointless since the object is being destroyed just as easily as it could assume that the memset isn't really necessary. Unfortunately, I have not seen a realistic example that proves the theory one way or the other.