| 144 | } |
| 145 | |
| 146 | void CSharpLanguage::finalize() { |
| 147 | if (finalized) { |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | if (gdmono && gdmono->is_runtime_initialized() && GDMonoCache::godot_api_cache_updated) { |
| 152 | GDMonoCache::managed_callbacks.DisposablesTracker_OnGodotShuttingDown(); |
| 153 | } |
| 154 | |
| 155 | finalizing = true; |
| 156 | |
| 157 | // Make sure all script binding gchandles are released before finalizing GDMono. |
| 158 | for (KeyValue<Object *, CSharpScriptBinding> &E : script_bindings) { |
| 159 | CSharpScriptBinding &script_binding = E.value; |
| 160 | |
| 161 | if (!script_binding.gchandle.is_released()) { |
| 162 | script_binding.gchandle.release(); |
| 163 | script_binding.inited = false; |
| 164 | } |
| 165 | |
| 166 | // Make sure we clear all the instance binding callbacks so they don't get called |
| 167 | // after finalizing the C# language. |
| 168 | script_binding.owner->free_instance_binding(this); |
| 169 | } |
| 170 | |
| 171 | if (gdmono) { |
| 172 | memdelete(gdmono); |
| 173 | gdmono = nullptr; |
| 174 | } |
| 175 | |
| 176 | // Clear here, after finalizing all domains to make sure there is nothing else referencing the elements. |
| 177 | script_bindings.clear(); |
| 178 | |
| 179 | #ifdef DEBUG_ENABLED |
| 180 | for (const KeyValue<ObjectID, int> &E : unsafe_object_references) { |
| 181 | const ObjectID &id = E.key; |
| 182 | Object *obj = ObjectDB::get_instance(id); |
| 183 | |
| 184 | if (obj) { |
| 185 | ERR_PRINT("Leaked unsafe reference to object: " + obj->to_string()); |
| 186 | } else { |
| 187 | ERR_PRINT("Leaked unsafe reference to deleted object: " + itos(id)); |
| 188 | } |
| 189 | } |
| 190 | #endif // DEBUG_ENABLED |
| 191 | |
| 192 | memdelete(managed_callable_middleman); |
| 193 | |
| 194 | finalizing = false; |
| 195 | finalized = true; |
| 196 | } |
| 197 | |
| 198 | Vector<String> CSharpLanguage::get_reserved_words() const { |
| 199 | static const Vector<String> ret = { |