summaryrefslogtreecommitdiff
path: root/modules/mono/mono_gd/gd_mono_internals.cpp
diff options
context:
space:
mode:
authorIgnacio Roldán Etcheverry <neikeq@users.noreply.github.com>2019-12-25 20:47:07 +0100
committerGitHub <noreply@github.com>2019-12-25 20:47:07 +0100
commitf90e8c41a21dcb28a53e4b1a4fc64904b8861aaa (patch)
treea17c66580c059c9bebcfa3e6feff80c0f9f09578 /modules/mono/mono_gd/gd_mono_internals.cpp
parentd711c57d767734887fbf0955a7b9902c54498a0d (diff)
parent0ef635c0e33fb925cdf12093da90d3977b23e107 (diff)
Merge pull request #34604 from neikeq/issue-27674
Mono/C#: Fix memory leak with new Reference instances created from C#
Diffstat (limited to 'modules/mono/mono_gd/gd_mono_internals.cpp')
-rw-r--r--modules/mono/mono_gd/gd_mono_internals.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/modules/mono/mono_gd/gd_mono_internals.cpp b/modules/mono/mono_gd/gd_mono_internals.cpp
index 3324ecb3a8..5b50f735e0 100644
--- a/modules/mono/mono_gd/gd_mono_internals.cpp
+++ b/modules/mono/mono_gd/gd_mono_internals.cpp
@@ -73,7 +73,7 @@ void tie_managed_to_unmanaged(MonoObject *managed, Object *unmanaged) {
script_binding.inited = true;
script_binding.type_name = NATIVE_GDMONOCLASS_NAME(klass);
script_binding.wrapper_class = klass;
- script_binding.gchandle = MonoGCHandle::create_strong(managed);
+ script_binding.gchandle = ref ? MonoGCHandle::create_weak(managed) : MonoGCHandle::create_strong(managed);
script_binding.owner = unmanaged;
if (ref) {
@@ -81,7 +81,9 @@ void tie_managed_to_unmanaged(MonoObject *managed, Object *unmanaged) {
// This way if the unmanaged world has no references to our owner
// but the managed instance is alive, the refcount will be 1 instead of 0.
// See: godot_icall_Reference_Dtor(MonoObject *p_obj, Object *p_ptr)
- ref->reference();
+
+ // May not me referenced yet, so we must use init_ref() instead of reference()
+ ref->init_ref();
}
// The object was just created, no script instance binding should have been attached