{"action":"created","issue":{"url":"https://api.github.com/repos/godotengine/godot/issues/16877","repository_url":"https://api.github.com/repos/godotengine/godot","labels_url":"https://api.github.com/repos/godotengine/godot/issues/16877/labels{/name}","comments_url":"https://api.github.com/repos/godotengine/godot/issues/16877/comments","events_url":"https://api.github.com/repos/godotengine/godot/issues/16877/events","html_url":"https://github.com/godotengine/godot/issues/16877","id":298878785,"number":16877,"title":"Memory leak with the gui_input() signal in C# / Mono","user":{"login":"Duehok","id":36293985,"avatar_url":"https://avatars0.githubusercontent.com/u/36293985?v=4","gravatar_id":"","url":"https://api.github.com/users/Duehok","html_url":"https://github.com/Duehok","followers_url":"https://api.github.com/users/Duehok/followers","following_url":"https://api.github.com/users/Duehok/following{/other_user}","gists_url":"https://api.github.com/users/Duehok/gists{/gist_id}","starred_url":"https://api.github.com/users/Duehok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Duehok/subscriptions","organizations_url":"https://api.github.com/users/Duehok/orgs","repos_url":"https://api.github.com/users/Duehok/repos","events_url":"https://api.github.com/users/Duehok/events{/privacy}","received_events_url":"https://api.github.com/users/Duehok/received_events","type":"User","site_admin":false},"labels":[{"id":73330064,"url":"https://api.github.com/repos/godotengine/godot/labels/bug","name":"bug","color":"ff2222","default":true},{"id":709269775,"url":"https://api.github.com/repos/godotengine/godot/labels/topic:mono","name":"topic:mono","color":"ffdd44","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/godotengine/godot/milestones/7","html_url":"https://github.com/godotengine/godot/milestone/7","labels_url":"https://api.github.com/repos/godotengine/godot/milestones/7/labels","id":2529217,"number":7,"title":"3.1","description":"","creator":{"login":"akien-mga","id":4701338,"avatar_url":"https://avatars0.githubusercontent.com/u/4701338?v=4","gravatar_id":"","url":"https://api.github.com/users/akien-mga","html_url":"https://github.com/akien-mga","followers_url":"https://api.github.com/users/akien-mga/followers","following_url":"https://api.github.com/users/akien-mga/following{/other_user}","gists_url":"https://api.github.com/users/akien-mga/gists{/gist_id}","starred_url":"https://api.github.com/users/akien-mga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akien-mga/subscriptions","organizations_url":"https://api.github.com/users/akien-mga/orgs","repos_url":"https://api.github.com/users/akien-mga/repos","events_url":"https://api.github.com/users/akien-mga/events{/privacy}","received_events_url":"https://api.github.com/users/akien-mga/received_events","type":"User","site_admin":false},"open_issues":739,"closed_issues":316,"state":"open","created_at":"2017-05-18T13:33:56Z","updated_at":"2018-02-22T12:36:04Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2018-02-21T08:26:49Z","updated_at":"2018-02-22T13:14:41Z","closed_at":null,"author_association":"NONE","body":"**Godot version: 3.0 stable, Mono 5.4.1.7**\r\n\r\n**OS/device including version: win 8.1**\r\n\r\n**Issue description:**\r\nC# only\r\nThe Godot.Object passed as argument of the signal gui_event(ev) is not disposed of when the method finishes and is not garbage collected unless explicitly disposed of with ev.Dispose().\r\nConsequence: wiggling your cursor above a control with a C# script that listens to the event without disposing of the object will leak Godot Objects at a rate of 60/second.\r\n\r\nThe workaround is to call ev.Dispose() at the end of the gui_input method. It is bad practice to dispose of an object outside of its creation scope because there can still be references to this object, but it is no longer valid! I forgot to test what happens if several scripts listen to the same gui_input(ev). If the same object is reused in the different scripts then I will get a runtime exception ObjectDisposedException.\r\n\r\nPossible solutions:\r\n1) Emergency patch: Add this in the C# warnings in the docs:\r\nhttp://docs.godotengine.org/en/latest/getting_started/scripting/c_sharp/c_sharp_basics.html#current-gotchas-and-known-issues\r\n\"Godot Objects passed as arguments of signals must be manually disposed of to avoid memory leaks. A method onGuiInput(Godot.Object ev) connected to the signal gui_input(object) must call ev.Dispose() before onGuiInput returns or ends.\"\r\nUnfortunately I cannot use github right now, so I cannot do a pull request.\r\n\r\n2) Best solution: automagically dispose of the object(s) when all the gui_input(ev) are finished.\r\n\r\n3) If an automatic generation of the methods connected to signals is done before the solution 2) is implemented, add an ev.Dispose in the methods' bodies to help not to forget it.\r\n\r\n**Steps to reproduce:**\r\nCreate any control, add a C# script to it, connect a method to the signal gui_input(object).\r\nRun the scene and wiggle your cursor above the control while looking at the number of godot objects in the debugger's monitor tab.\r\n\r\n**Minimal reproduction project:**\r\n[InputEventObjectLeak.zip](https://github.com/godotengine/godot/files/1743286/InputEventObjectLeak.zip)"},"comment":{"url":"https://api.github.com/repos/godotengine/godot/issues/comments/367676914","html_url":"https://github.com/godotengine/godot/issues/16877#issuecomment-367676914","issue_url":"https://api.github.com/repos/godotengine/godot/issues/16877","id":367676914,"user":{"login":"Duehok","id":36293985,"avatar_url":"https://avatars0.githubusercontent.com/u/36293985?v=4","gravatar_id":"","url":"https://api.github.com/users/Duehok","html_url":"https://github.com/Duehok","followers_url":"https://api.github.com/users/Duehok/followers","following_url":"https://api.github.com/users/Duehok/following{/other_user}","gists_url":"https://api.github.com/users/Duehok/gists{/gist_id}","starred_url":"https://api.github.com/users/Duehok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Duehok/subscriptions","organizations_url":"https://api.github.com/users/Duehok/orgs","repos_url":"https://api.github.com/users/Duehok/repos","events_url":"https://api.github.com/users/Duehok/events{/privacy}","received_events_url":"https://api.github.com/users/Duehok/received_events","type":"User","site_admin":false},"created_at":"2018-02-22T13:14:41Z","updated_at":"2018-02-22T13:14:41Z","author_association":"NONE","body":"A quick test seems to indicate that if one gui_input(object ev) is onnected to several metods, disposing of the object(s) in each method works fine. So the workaround is useable."}}
{"actor":{"display_login":"Duehok"}}