Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | GlaDOSik | |
Old Version | Published before Godot 3 was released. |
Hi,
I’m working on editor plugin. The important code does this: Each time the user clicks on MeshInstance, new Mesh is generated by SurfaceTool and it’s set in MeshInstance.set_mesh(). The old resource is no longer in use and should be freed by engine. Quick look at Task Manager showed me that every time I click, 20-80 kB of data is allocated.
I’m sure the MeshInstance.set_mesh() is leaking because if I just generate new mesh and don’t set it, no memory is leaking. Is there a way to force old mesh resource to free?
Important part of the code:
var newWireMesh = generateWireframeMesh(meshTool)
meshInstance.get_meta("orgMesh").surface_remove(0)
meshTool.commit_to_surface(meshInstance.get_meta("orgMesh"))
meshInstance.get_mesh().surface_remove(0)
meshInstance.set_mesh(newWireMesh)
The whole script is on Pastebin
I fixed the leak. If you do something similar as me, a good practice is to reuse the Mesh. You can pass the old mesh to SurfaceTool.commit(oldMesh)
. It will create a new surface with your new data. Don’t forget to delete your old surface first: oldMesh.surface_remove(0)
. It’s only a bypass tho. The leak is still imminent.
GlaDOSik | 2016-08-25 20:23