-
-
Notifications
You must be signed in to change notification settings - Fork 245
base()
+ base_mut()
no longer clone Gd
pointer
#1302
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
Conversation
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1302 |
@@ -493,7 +493,7 @@ pub trait WithBaseField: GodotClass + Bounds<Declarer = bounds::DeclUser> { | |||
/// ``` | |||
#[allow(clippy::let_unit_value)] | |||
fn base_mut(&mut self) -> BaseMut<'_, Self> { | |||
let base_gd = self.base_field().__constructed_gd(); | |||
let weak_gd = self.base_field().__constructed_gd_weak(); | |||
|
|||
let gd = self.to_gd(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.to_gd
still increments ref count.
By printing the instance id, the memory leak occurs at the the script instance test:
|
I can reproduce leak in ScriptInstanceTest.gd without any tweaks 🤔. The reason is simple though – to_script_gd increases refcount: gdext/godot-core/src/obj/base.rs Lines 301 to 312 in f62ab24
and then it is being dropped weak: gdext/godot-core/src/obj/guards.rs Lines 298 to 311 in f62ab24
Changing it to |
I'm curious why does it create 2 leaks (and orphans) instead of
|
f62ab24
to
ee81efe
Compare
Thanks a lot to both of you for the debugging help, very nice ❤️ It works now, but it's a bit flimsy. I'm considering to abstract this in a |
ee6373d
to
d6a0dae
Compare
d6a0dae
to
fc389f8
Compare
I believe we still can't use |
Could you maybe provide an |
My proof is here: master...beicause:gdext:base_mut_init_drop It works, but I give |
base()
+base_mut()
currently clone theGd<T>
, which causes refcount increments in case ofT: Inherits<RefCounted>
.Theoretically this shouldn't be necessary, since the guards hold a lifetime tied to the "parent" object (the original
Gd
).This PR experiments with ways to avoid this, but is currently blocked on a memory leak that needs further investigation. Not sure if this approach is feasible at all.