godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.15k stars 21.19k forks source link

`reload()` of `GDScript` causes memory leak #99169

Open jinyangcruise opened 2 days ago

jinyangcruise commented 2 days ago

Tested versions

System information

Windows 11, Vulkan API 1.3.280 - Forward+ - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce RTX 3060 Ti

Issue description

Can see memory increasing and Object count increasing by this code:

extends Node2D

func _ready() -> void:
    for i in 100:
        for j in 10:
            var a = GDScript.new()
            a.source_code = "extends Object\nvar value = 2212"
            a.reload()
        await get_tree().create_timer(1).timeout
屏幕截图 2024-11-13 175654

Object's count won't increase without using reload() however we must use reload() to let the code take effect if we want to use somthing like var obj = a.new()

Steps to reproduce

  1. run MRP
  2. see monitor

Minimal reproduction project (MRP)

test_resource_free.zip

dalexeev commented 2 days ago