Marshal.DestroyStructure is marked with the Pure attribute in the .NET Framework but I'm unsure as to why when it clearly has an effect on the context calling it.
The state is modified (the pointer is freed) even if it doesn't directly modify the pointer instance itself.
Implied in the question is: Can a developer, in good faith, mark something as Pure even if she knows it modifies the context's state indirectly?
It's Pure in the sense that it has no effect on visible managed state, which means, for the purpose of code contracts, calling the method could not violate class invariants.
Granted, it's slightly misleading to think of the method as Pure, as it does have side effects, even if those side effects are not visible. They are observable (if you try to use the pointer after freeing it, you'll cause a failure), but not exactly visible (you can't tell without trying to use the pointer that something is wrong.) I'm not sure what the motivation was for marking the method Pure, since I can't see why it would have ever been used in a Contracts block, but I'm guessing there must have been some reason somewhere deep in the BCL contracts that required it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With