Memory leak?

When my project runs in the web player I noticed that the memory consumption gradually rises without stopping. The project does a number of http calls, some calls are downloading while streaming files stored in a server, other calls are continuously running updating the mainTexture of various 3d objects in the world. I wanted to ask whether this memory problem is because of the http calls or Unity? I blame the calls but any advice would be valuable.

If you create any Unity assets–materials, textures, sounds, etc–you must destroy them when you’re done with them.

Monitor your object count with: http://www.unifycommunity.com/wiki/index.php?title=DetectLeaks

Thank you for the help. Create on the fly or this accounts for assets imported/added through the editor?

I’m pretty sure this applies only to things created on the fly through scripts as far as leaking since the other assets are loaded into memory when the player is initially loaded.

It seems that I am creating textures continuously with my script instead of overwriting existing ones. However I cannot use destroy since that destroys the gameobject. Any ideas?

Well, you should be able to do the following:

var theCreatedTexture : Texture2D;

........BLAH.........
........BLAH.........
........BLAH.........

Destroy(theCreatedTexture);

I filed a bug however, because this doesn’t seem to work and, while maybe a little slower (maybe completely stopped for a minute or two), the memory usage will eventually keep going through the roof. Rather, it doesn’t seem to actually Destroy the Texture2D Object

Maybe you can confirm this too Antonios and file a bug report with an included project as mine wasn’t the best example. :slight_smile:

Ok I made it worked by using DestroyImmediate which forces destruction. However I noticed that while my character is moving through the world the meshes count slowly increases. Does Unity load the meshes dynamically through LOD? I thought that the world was not loading on the fly but immediatelly hence the download at the loading screen.