Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Remove calls to GC.KeepAlive







Breaking Change

Non Breaking

Classes use SafeHandle but still contain calls to GC.KeepAlive.

If converting to SafeHandle usage, remove all calls to GC.KeepAlive (object). In this case, classes should not have to call GC.KeepAlive, assuming they do not have a finalizer but rely on SafeHandle to finalize the OS handle for them. Even though the cost of leaving in a call to GC.KeepAlive might be negligible in terms of performance, the perception that a call to GC.KeepAlive is either necessary or sufficient to solve a lifetime issue that might no longer exist makes the code harder to maintain.

Remove calls to GC.KeepAlive.

You can suppress this warning only if it is not technically correct to convert to SafeHandle usage in your class.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.