Get the latest tech news

Finalizers are tricker than you might think. Part 2


In the previous part we discussed why the finalizers should only deal with unmanaged resources and in this post I want to show that this is not as simple as it sounds.

In the previous part we discussed why the finalizers should only deal with unmanaged resources and in this post I want to show that this is not as simple as it sounds. Now, this is safe, since the handle instance itself is not eligible by the GC until the end of the method due to GC.KeepAlive(and the GC.KeepAlive is very important here to avoid race condition that could cause the resource cleanup during the native call). At least your users are safe and they won’t get heisenbugs due to very strange and hard to reproduce race conditions between their code and the GC finalization.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Finalizers

Finalizers