-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GC-resistant GObject subclasses #64
Conversation
The object needs an additional reference before it is passed to GObject::Object.new because a full transfer means that the recipient owns a ref on the value.
This reference manager allows checking for memory leaks in the specs as its behaviour is deterministic.
Nice, I'll try to review this in detail this week. If I understood correctly the pros and cons are:
cons:
|
Yes, but you can have multiple The other ones - yes. Additionally I'd say being able to initialize from C is more important than GC-resistancy because you can use gtk builder. |
I'll close this MR, despite of it include other features besides GC resistant objects, the main aim was GC resistance. Closed in favor of #107 |
This PR allows GObject subclasses to be GC-resistant.
Actually, the biggest part of this PR is allowing GObjects to be created from C (g_object_new) without fearing the GC, which requires creating the crystal object from C and retrieving it in the constructor, not creating the crystal object and then setting the pointer.
This time, the user does not need to create multiple classes, manage references (or something similar) becuase the PR uses toggle refs.
A toggle ref is basically a reference telling us whether there are other references besides it or not. If other references exist, we put a pointer to the object in some global array or remove it otherwise.
Additionally, the last two commits add support for defining one
initialize
method per class. The arguments of the method are exposed as construct-only GObject properties, so you can set them even from C. Because GObject properties alone are maybe not as versatile as some classes require it, you can also use the newRefProp
annotation. Here's how this looks in action:What you can see is:
self.new
method.@string
), which you would be able to set even in a gtk .ui file.GObject::RefProp
. For these args, only aPointer(Void)
to a variable is transferred via a GObject property. With this mechanism, most crystal types can be transferred over GObject for constructing.You can now initialize it:
This
self.new
method allows setting all GObject properties (defined in C or Crystal) and all initialize arguments in one method.As a little demonstration, I have created a blueprint for an app I am currently working on:
Which results in this window:
To allow this PR to work, multiple breaking changes had to be made and I expect most GObject subclasses to break.