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
0
Question by infinitypbr · Dec 20, 2012 at 02:54 AM · texturesmemory

How to Remove Textures from Memory (Downloaded During Play)

Hello!

I have a little project that uses photos downloaded from a server as textures for each game level. The object stays the same, but each level downloads a smallish 100-400Kb jpg image.

While looking at the profiler in XCode, running the app on the iPad, it's obvious that each time an image is downloaded, memory usage increases 20-30Mb. After about 7 images, the app will quit (receiving memory warnings along the way).

How can I free up the memory after I'm done with each image (texture) I've downloaded? I don't see the textures in the hierarchy during gameplay in Unity, so I'm not sure how to reference them for Destroy.

Thanks for any help!

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

4 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by infinitypbr · Dec 20, 2012 at 03:20 AM

I've answered my own question, and of course the answer is simple.

On the script attached to the object, when it's time to switch, before loading a new texture etc, I simply added:

 Destroy (renderer.material.mainTexture);

Now system memory goes up just 5MB per load, rather than 20-30. There's still an issue it seems, but it's not as bad at this point.

Comment
Add comment · Show 3 · 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 Karthy07 · Feb 18, 2015 at 06:54 AM 1
Share

Try using

Resources.UnloadAsset(yourTexture);

I think this might help you.

avatar image fschneider Karthy07 · Mar 11, 2016 at 12:55 PM 0
Share

Are you sure Resources.UnloadAsset will be working with content downloaded from a server? $$anonymous$$y interpretation of the documentation was that this particular method would only work for Assets loaded from the Resources folder.

avatar image king_opping · Jan 28, 2019 at 05:09 AM 0
Share

i implement this, and reduce my apps memory greatly, as in my apps users may swipe to some images that requested to server. thanks!.

avatar image
2

Answer by Mgayar · Sep 13, 2018 at 01:16 AM

For my case, calling that helped: Resources.UnloadUnusedAssets();

Comment
Add comment · 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
1

Answer by drudiverse · Dec 13, 2015 at 10:17 PM

check out the best compression for images in unity... perhaps //cube.renderer.material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);

Comment
Add comment · 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
0

Answer by kxqnjy · Jan 21, 2019 at 03:08 PM

A similar issue happened, my Android phones at most support 4GB memory per app using it. But for one of my Unity project, it requires at most 7GB memory, and yes, most of the memory usage is because the texture loaded in the memory. But now I am wondering if two objects are using the same texture, will the memory usage be twice of the one object case? Or just be twice?

Comment
Add comment · 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

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

Sprite-based animation - mobile memory issue 0 Answers

How to have 2 sets of textures and make sure only one is loaded? 0 Answers

Textures suddenly failing to load on iOS during long session 0 Answers

Some textures don't load on iOS 0 Answers

reading a texture that was created via script runtime and not saved 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