- Home /
How to destroy instantiated object
I have use Asset Bundles. From them i try to load a model (eg monkey) and a texture (same name). Now when i load them i look at the profiler and see that the mesh count increases by 1 and the materials increase by 1 or 2 depending on how many there are. So when i no longer need the model (eg when it leaves the screen) i call destroy(m3dModel) on it but I check that my mesh and my material and my texture count stay the same aswell as the total memory allocated. Now normally this would not be a problem but I have 350 models and since i build for android the application will crash after too much data has been allocated.
I have tried to destroy all textures and everything but it does not change. I even went about destroying each component in a for loop and it still stays the same. Can anyone help me with this. Its kinda annoying that Unity objects are not actually destroyed when I call destroy on them.
Answer by hvilela · Oct 01, 2012 at 05:12 PM
You have to unload your loaded bundle.
bundle.Unload(false);
Yes but that removes the whole bundle from memory. I still need it to load other objects from it (other models). $$anonymous$$y app is an Augmented reality thing.
Doesn't that only unload something that you instanciated with Resources.load()??
I never had to unload like you need, so I'm just guessing.
I have found where my leak is. I use renderer.material.mainTexutre = (Texture2D)(texture.asset) which creates a new material. Thanks for your help. Also i tried Resources.UnloadUsusedAssets() and it does work even for assetbundles.