Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by ChrisBudden · Jan 07, 2014 at 11:00 AM · texturememory-leak

Possible Texture memory leak

I'm having a major memory leak issue possibly related to texture memory

In our program, a large number of textures are loaded into a list at the beginning on the program. The user can select one of these images and it pops out onto a moveable tile that can then be closed. Unfortunately the new tile seems to use more memory and doesn't release it afterwards.

The function that sets the texture of the new tile is effectively this:

 public void initTexture(texture _input)
 {
     renderer.material.mainTexture = _input
 }

In my main script I call both Resources.UnloadUnusedAssets() and GC.collect

Is there anything I've missed? Is there some specific way to unload the texture? I was under the impression Unity only held one copy of each texture, does my tile class create and store a new version of it?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Kolodej · Jan 10, 2014 at 12:20 PM

Hi, consider using Texture2D.Destroy / DestroyImediate. It should be working properly.

 private void UpdateMaterialMainTexture(Texture2D texture) {
         
         // destroy old if exists
         if (_currentMainTexture != null) {
             Texture2D.DestroyImmediate(_currentMainTexture, true);
         }
         
         // assign a new texture
         _currentMainTexture = texture;        
         
         // set a new material texture
         this.renderer.material.SetTexture("_MainTex", _currentMainTexture);
     }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ChrisBudden · Jan 24, 2014 at 01:57 PM 0
Share

I don't actually store the image in the script itself, the images are loaded into a List in the content script, and passed into my function when the "Tile" is created, where it manually sets the Tile's texture to said image.

As such, there is nothing to destroy, and attempting to destroy the tiles renderer.material.mainTexture gives a warning about deleting assets.

At present we are getting around the problem by restarting the program at midnight every night and avoiding spawning excessive numbers of assets, but this is far from ideal, as large videos are also loaded into memory at some points!

EDIT: I can also confirm that they are the same texture, as calling "Resources.UnloadAsset(Tile.renderer.material.mainTexture)" deletes the asset on all individual copies of the tile.

I've been researching this and have found the issue on a number of questions, I think it is more likely to be an issue with Instantiating and Destroying prefab objects

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Runtime Generated Textures Not Releasing Memory 0 Answers

Download images from url, save to device, load into UGUI 4 Answers

New blank project with 3 leaked textures ??? 1 Answer

Assigning UV Map to model at runtime 0 Answers

Loading external Image as Texture2D increases memory consumption dramatically on iOS 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges