mono / gtk-sharp

Gtk# is a Mono/.NET binding to the cross platform Gtk+ GUI toolkit and the foundation of most GUI apps built with Mono
http://www.mono-project.com/GtkSharp
Other
426 stars 141 forks source link

Probably good finalizer optimizations? #199

Closed Therzok closed 7 years ago

Therzok commented 7 years ago

This patch introduces 2 new mechanisms:

  1. Promoting only the safehandle + toggleref of a given GLib.Object derived class.
  2. Removes finalizer queues on the UI thread with simple unrefs. GLib is thread safe by itself, so unref-ing shouldn't cause any issues.
  3. Modify some classes so their finalizers aren't run if the handle isn't owned
alanmcgovern commented 7 years ago

Removes finalizer queues on the UI thread with simple unrefs. GLib is thread safe by itself, so unref-ing shouldn't cause any issues.

GLib might be threadsafe, but Gtk is not. The final unref causes the dispose and finalize methods to be invoked, and they must be invoked on the main thread.

Therzok commented 7 years ago

By reading here: https://developer.gnome.org/gtk2/stable/GtkObject.html#gtk-object-destroy

The unrefs are all called by Destroy, which is called on the UI thread. The rest of the objects are thread-safe due to not being tied to GtkObject.

alanmcgovern commented 7 years ago

That doesn't account for the native Dispose, the native finalize or the safe usage of g_object_weak_ref which will now become unsafe.

Therzok commented 7 years ago

Superseded by #200