Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh Memory Leak #23

Open
KowsarAtz opened this issue Feb 28, 2022 · 3 comments
Open

Mesh Memory Leak #23

KowsarAtz opened this issue Feb 28, 2022 · 3 comments

Comments

@KowsarAtz
Copy link

KowsarAtz commented Feb 28, 2022

In chunk.cs CreateMesh, before assigning the new mesh to meshFIlter (meshFilter.mesh = mesh;), we have to destroy the old mesh (Object.Destroy(meshFilter.sharedMesh);); otherwise we will face memory leak. The leak is disastrous especially when you put lots of blocks in game (>1000).

@TeriyakiGod
Copy link

Can you explain why? Why do we have to destroy the shared mesh and why does it cause a leak?

@KowsarAtz
Copy link
Author

Can you explain why? Why do we have to destroy the shared mesh and why does it cause a leak?

Sorry if I'm answering late. Unused mesh or material will not be collected by the garbage collector, So when you are replacing the old mesh with the new one, you have to destroy the old one yourself. In order to access the old mesh, you have to use meshFilter.sharedMesh instead of meshFilter.mesh because the latter will give a new instance of the mesh and you don't want that.

I suggest reading the following links as well:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@TeriyakiGod @KowsarAtz and others