Repository: godot
Issue: [Bug Mono] Error - Mono: Domain finalization timeout on closing the application with large number of objects.
Labels: bug,needs testing,topic:dotnet

### Godot version

3.4 RC1, 3.3.4

### System information

Windows 10, NVidia GTX 1660Ti

### Issue description

I have a project which has a lot of TextureRects - to be precise currently about 16000+, RAM usage is just about ~1.5 GB.

_I'd like to note in advance that I'm not 100% how to isolate this problem and I also did not manage to put together the minimum requirement project since the number of images required for it is way beyond limits of github. But I can provide my full project (without the images) if needed, it's an image gallery so it's not a large or a complex project. But I do not think the problem comes from my code as noted below._

**Error I get is:**
_unload_scripts_domain: Mono: Domain finalization timeout.
At: modules/mono/mono_gd/gd_mono_cpp:1049

I tested thsi on Win 10 with 3.4RC1, 3.3.4 with the same error, editor run as well as exported project - thought in some cases editor ran project sometimes did not cause the error msot of the time yes but sometimes it did not, I assume since the editor is running GC has enough time to finalize?
`
    if (!mono_domain_finalize(scripts_domain, 2000)) {
        ERR_PRINT("Mono: Domain finalization timeout.");
    }
`

If it's in any way related I use Task.Run in async to run img texture load in threads to speed up the process, I don't use them after that or keep any reference to them but just in case wanted to mention that I use a few threads but their work gets finished before  I try closign the app or anything obviously.

**Issue:**

My gallery loads about 16000 textures and addes them as TextureRects to a Grid node. The problem comes when the application is closing. The above mentioned error occurs and this freezes the app and it requires killing the process in the task manager, this happens everytime.
I keep c# references to all the images in a list.

**Solving the issue requires:**

Leaving app open for 20-30 mins and then closing which does not causes the error to appear.
Loading less images (few thousands don't result in the error) - though this is not the way I can afford to go.
After opening the app and loading the images call `GC.Collect` and then you can close immediately (the collection takes split of a second) no problem.

Since the issues is solved by calling GC I do not think the problem is in my code, I discussed this on discord with others and they share the same opinion an recommended me to report it here, maybe there's some problem with GC timing when the godot application gets closed when you have a lot of objects?

My current workaround is this for my main node (and it works like a charm, the entire app closes in a split of a second with this):

```
public override void _Notification(int what)
{
  base._Notification(what);

  if (what == MainLoop.NotificationWmQuitRequest)
  {
    GC.Collect();
    GD.Print("GC Collect finished.");
  }
}
```
(Perhaps quick Collect cleans some references thus finalize doesn't need run for that long and stays under the above mentioned 2000ms limit? Why 2000ms, I don't know.)


### Steps to reproduce

As described above the reporoduction is kind of unsure since I'm not 100% sure what causes the behaviour to begin with and with the number of images/ojbects needed for this.

Currently my only recommendation is to put together a loop which loads thousands of texturerects and displays them and then trying to clsoe the app and repeating it with increased number of images until you hit the limit I guess?

If someone has a better idea please let me know, I'll try my best to put something reasonable together.

### Minimal reproduction project

_No response_