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 kromenak · Oct 16, 2013 at 07:26 PM · texturewwwmemory

What is the correct way to remove assets from memory?

I'm having some trouble finding the correct way to handle this, and thought I'd see if anyone on here has some insight.

Basically, I'm loading Facebook profile pictures from the internet using the WWW class, like so:

 // Start downloading the image and wait.
 WWW www = new WWW(imageUrl);
 yield return www;
             
 // Save texture;
 if(www.textureNonReadable != null) 
 {        
     picture = www.textureNonReadable;
 }

I've found that when I load pictures in this way, they do not seem to get garbage collected automatically. I imagine I need to "delete" the texture asset for it to be removed from memory. Problem is, there are a number of ways to do this:

 GameObject.Destroy(picture);
 GameObject.DestroyImmediate(picture);
 Resources.UnloadAsset(picture);
 picture = null;

Even trying each of those options, I've found using the profiler that the texture seems to only truly be removed from memory when I call "Resources.UnloadUnusedAssets( )".

So, ultimately, for reference, what is the correct way to remove assets like this from memory and avoid a memory leak? Or should the picture be garbage collected automatically when all references are "null" as expected?

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
0
Best Answer

Answer by Eric5h5 · Oct 16, 2013 at 08:29 PM

You answered your own question...Resources.UnloadUnusedAssets. Unity objects are not part of Mono and are never garbage collected on their own, although loading a new level will destroy all objects and do Resources.UnloadUnusedAssets.

Comment
Add comment · Show 2 · 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 kromenak · Oct 16, 2013 at 10:05 PM 0
Share

Ok, gotcha. Is Resources.UnloadAsset() supposed to work like "UnloadUnusedAssets" for a single asset? Because in testing, it didn't seem to behave that way (after calling UnloadAsset, the asset seemed to remain in memory, according to the Unity profiler).

avatar image Eric5h5 · Oct 16, 2013 at 10:12 PM 0
Share

I've never used it, but according to the docs, it's only for assets that are stored on disk.

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

15 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

Related Questions

the texture appear rubbish 1 Answer

Free memory after WWW.LoadImageIntoTexture 1 Answer

Large memory footprint increase when assigning a GUITexture from a WWW Object on iPad 1 Answer

Loading imagesequence at runtime - memory problem 1 Answer

Why do larger www textures take huge amounts of memory? 1 Answer


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