Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
4
Question by jose · Aug 04, 2011 at 08:18 AM · texture2dmemory

Why does a 1024*1024 Texture2D use so much memory?

Why does a 1024*1024 ARGB32 Texture2D use more than 8MB total memory? I think the correct cost is 4MB (4MB = 1024 1024 32bit / 8 / 1024 / 1024).

I just did a test on Unity3.3 pro. Create an empty project only included a empty scene. Create bellow script:

 using UnityEngine;
 public class NewBehaviourScript : MonoBehaviour {

     public Texture2D tt;
     void OnGUI () {
         if (GUILayout.Button("Create Texture2D")) {
             tt = new Texture2D(1024, 1024, TextureFormat.ARGB32, false);
             Resources.UnloadUnusedAssets();
         }
     }
 }

Drag this script to scene.

When I click the button on run time. The profiler of unity display that Textures memory add 4MB but Total memory add more than 8MB.

Here are two screenshots:

Before Create a 1024*1024 ARGB32 Texture2D:

 Total: 270.5 MB Delta: 0 B
 Texture: 770 / 2.5 MB
 Meshes: 26 / 74.9 KB
 AnimationClips: 0 / 0 B
 Total Object Count: 1134

After Create a 1024*1024 ARGB32 Texture2D:

 Total: 279.3 MB Delta: 0 B
 Texture: 771 / 6.5 MB
 Meshes: 26 / 74.9 KB
 AnimationClips: 0 / 0 B
 Total Object Count: 1116






Comment
Add comment · Show 6
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 GuyTidhar · Aug 04, 2011 at 08:34 AM 0
Share

Have you got mipmaps on?

avatar image jose · Aug 04, 2011 at 08:48 AM 0
Share

@guyt no mipmaps

avatar image StephanK · Aug 04, 2011 at 09:22 AM 0
Share

What happens when you do this without the unload unused assets? If you look at the texture display it says that it added exactly 4$$anonymous$$B texture memory.

avatar image jose · Aug 04, 2011 at 09:42 AM 0
Share

@spree 1 , If I do this without the unload unused assets, it still added more than 8$$anonymous$$B total memory. But in fact, I just create a 1024*1024 Texture.

avatar image CHPedersen · Aug 04, 2011 at 09:48 AM 0
Share

Curious. Have you tried building the app, then running it standalone outside the editor and monitor the memory increase in the Task $$anonymous$$anager (on Windows, at least) at the point where you know the texture gets created?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Waz · Aug 04, 2011 at 12:10 PM

Texture2D's created in code are read-write, so there is a copy outside texture memory, just as for an imported Texture2D with isReadable set to true. When you have finished modifying the Texture2D, use the makeNoLongerReadable parameter of Texture2D.Apply() to discard the in-memory copy.

Comment
Add comment · Show 4 · 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 Statement · Aug 04, 2011 at 12:12 PM 0
Share

Ah, this makes some sense.

avatar image Favo-Yang · Aug 05, 2011 at 06:54 AM 0
Share

I tried the Apply(false, true); right after creating the texture. (and even try to set a pixel before it to make sure it indeed need "apply"), but profiler still shows overview consumed 8$$anonymous$$B+ memory. I did call Resources.UnloadUnusedAssets(); and GC.Collect() after apply, no help. I can only assume that is a "bug" of texture 2D implementation.

Refs, function Apply (update$$anonymous$$ipmaps : boolean = true, makeNoLongerReadable : boolean = false) : void

avatar image xilliah · Jun 29, 2012 at 09:13 PM 0
Share

Unity seems to keep a copy in the general ram in order to quickly be able to re-upload it into the video ram. Notice that the video ram (Texture $$anonymous$$emory) is very rapid in following changes in the scene and I suppose this is the Unity philosophy of dealing with this kind of problem. I assume this could even be working together with culling. Personally I don't need this for everything, for example GUI textures that are always visible. And I don't $$anonymous$$d having to reload popup textures. Really it's mostly just annoying.

avatar image Eric5h5 · Jun 29, 2012 at 10:52 PM 0
Share

It doesn't keep a copy if you use the makeNoLongerReadable parameter like Warwick Allison said. VRA$$anonymous$$ is virtualized anyway and not something that Unity needs to involve itself with in that way.

avatar image
0

Answer by Statement · Aug 04, 2011 at 09:56 AM

I am not sure if temporary garbage adds to the count or not. If it does, then those 8+ MB might actually be to some part garbage that haven't been collected.

You could try to collect all garbage to see if it does any difference.

 using UnityEngine;
 public class NewBehaviourScript : MonoBehaviour {
     public Texture2D tt;
     void OnGUI () {
         if (GUILayout.Button("Create Texture2D")) {
             tt = new Texture2D(1024, 1024, TextureFormat.ARGB32, false);
             Resources.UnloadUnusedAssets();
 
             // ************************************************************
             // Lines below are added to collect garbage and wait for thread
             // ************************************************************
 
             GC.Collect();
             GC.WaitForPendingFinalizers();
         }
     }
 }


Comment
Add comment · Show 5 · 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 jose · Aug 04, 2011 at 10:41 AM 0
Share

Thanks for your help. But it dose not any difference.

avatar image Statement · Aug 04, 2011 at 10:53 AM 0
Share

I find it a bit "scary" to see a doubling in memory usage from the expected results. What happens if you create 2 textures? It could maybe be some pooling algorithm that allocate memory chunks up in advance.

avatar image jose · Aug 04, 2011 at 11:08 AM 0
Share

If I create two textures, It added about 20$$anonymous$$B total memory

avatar image Statement · Aug 04, 2011 at 11:20 AM 0
Share

Wait, what, so 1 texture (estimated 4$$anonymous$$B) added 8.8$$anonymous$$B, and 2 textures (estimated 8$$anonymous$$B) added ~20$$anonymous$$B (17.6$$anonymous$$B)?

avatar image CHPedersen · Aug 04, 2011 at 11:43 AM 0
Share

I just tested this on my machine and got the same result in the profiler. Deeply disconcerting, actually. Looking forward to some wizard's explanation.

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

8 People are following this question.

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

Related Questions

Memory issues 1 Answer

Does Animator with Sprite Animation clip cause memory issue ? 0 Answers

Using baked textures and about texture sizes? 1 Answer

Texture Doubled in size in RAM Profiler 3 Answers

maximum slice in a sprite sheet 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