MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / refcount_decremented

Method refcount_decremented

modules/mono/csharp_script.cpp:1883–1919  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1881}
1882
1883bool CSharpInstance::refcount_decremented() {
1884#ifdef DEBUG_ENABLED
1885 CRASH_COND(!base_ref_counted);
1886 CRASH_COND(owner == nullptr);
1887#endif // DEBUG_ENABLED
1888
1889 RefCounted *rc_owner = Object::cast_to<RefCounted>(owner);
1890
1891 int refcount = rc_owner->get_reference_count();
1892
1893 if (refcount == 1 && !gchandle.is_weak()) { // The managed side also holds a reference, hence 1 instead of 0
1894 // If owner owner is no longer referenced by the unmanaged side,
1895 // the managed instance takes responsibility of deleting the owner when GCed.
1896
1897 // Release the current strong handle and replace it with a weak handle.
1898
1899 GCHandleIntPtr old_gchandle = gchandle.get_intptr();
1900 gchandle.handle = { nullptr }; // No longer owns the handle (released by swap function)
1901
1902 GCHandleIntPtr new_gchandle = { nullptr };
1903 bool create_weak = true;
1904 bool target_alive = GDMonoCache::managed_callbacks.ScriptManagerBridge_SwapGCHandleForType(
1905 old_gchandle, &new_gchandle, create_weak);
1906
1907 if (!target_alive) {
1908 return refcount == 0; // Called after the managed side was collected, so nothing to do here
1909 }
1910
1911 gchandle = MonoGCHandleData(new_gchandle, gdmono::GCHandleType::WEAK_HANDLE);
1912
1913 return false;
1914 }
1915
1916 ref_dying = (refcount == 0);
1917
1918 return ref_dying;
1919}
1920
1921const Variant CSharpInstance::get_rpc_config() const {
1922 return script->get_rpc_config();

Callers

nothing calls this directly

Calls 4

MonoGCHandleDataClass · 0.85
get_reference_countMethod · 0.80
is_weakMethod · 0.80
get_intptrMethod · 0.80

Tested by

no test coverage detected