According to this answer by a reasonably reliable source, in C#, an object can be collected as soon as the GC can prove it will no longer be used, even if references to it still exist. This can cause surprising early finalization issues.
If you specifically want to delay collection of an object until a certain point, what would be the best way to do so? We can't do it by simply keeping a reference to the object, and if we try to make some simple use of the reference to stop the GC, such operations would likely be optimized away. What can we do?
(The motivation for this question is an older question in Java where someone wanted to ensure that the referents of a list of WeakReferences wouldn't be collected while the WeakReferences were being sorted by their referents. As such, an explanation of how Java's behavior is similar or different to C#'s in this case and a solution for the corresponding problem in Java would also be appreciated.)