• 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 Serath · Mar 24, 2014 at 10:05 PM · animationandroidspritesheetmemory leak

[ANDROID] Downloading large (4000x4000) textures causes a lot of memory consumption.

So, we're developing a game where we need to download for each game a certain gif. We have split these gifs into spritesheets and they are stored in our database, w$$anonymous$$ch we can access through the Rest communicating with Server.

Problem: After I load a spritesheet from the outside, thats about 4000x4000 pixels, the game eats like 100MB of RAM, w$$anonymous$$ch is a problem here. Here is a snippet of my code:

     private IEnumerator LoadImageFromURL(_AnimatedSprite a)
     {
         Debug.Log("Checking url");
         WWW www;
         
         if(a.HasThumbnail)
         {
            www = new WWW(a.URL);
         }
 
         else
         {
             www = new WWW(a.URLThumnail);
         }
         
        
         Debug.Log("Started downloading");
          
         yield return www;
 
         if (www.error != null)
         {
               Debug.Log("Error!");
               Switcher.mb.showMessage(MessageBox.MessageType.negative, www.error);
               a.Loaded = true;  
             running = false;
         }
 
         else
         {
                 
             if (!a.HasThumbnail)
             {
                 www.LoadImageIntoTexture(a.Thumbnail);
                 
                 // a.Thumbnail.LoadImage(www.bytes);
                // a.Thumbnail.Compress(false);
                 a.HasThumbnail = true;
             }
             
             else
             {
                 www.LoadImageIntoTexture(a.SpriteSheet);
                 // a.SpriteSheet.LoadImage(www.bytes);
                // a.SpriteSheet.Compress(true);
                 a.Loaded = true;
             }
    
             Texture2D.Destroy(www.texture);
             Texture2D.Destroy(www.textureNonReadable);
             Resources.UnloadUnusedAssets();
         }
         
         running = false;
         www.Dispose();
         www = null;
         string s = a.HasThumbnail ? "animation" : "thumbnail";
         Debug.Log("Finished downloading " + s);
     }

Any help is appreciated. Thanks!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mavii_ege · Mar 24, 2014 at 11:03 PM

Try to compress images and cut to pieces like part 1,2,3

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 Serath · Mar 25, 2014 at 12:25 AM 0
Share

Cutting it to pieces won't help. You still load a bunch of images combined gives the same memory consumption. Tried to compress it with pngout, didn't help.

avatar image mavii_ege · Mar 25, 2014 at 12:30 AM 0
Share

check this thread http://answers.unity3d.com/questions/508476/does-using-half-res-in-the-quality-settings-reduce.html

avatar image RyanZimmerman87 · Mar 25, 2014 at 12:33 AM 0
Share

Hmm I'm just kinda curious about your project. Is there a reason why you have them downloading these images from the server?

Mobile platforms seem to be TERRIBLE with texture compression so this problem does not really surprise me when combined with communicating with the server as well.

If you are just doing 1 sprite at a time for the user, it may be better to have a small file for each image because right now it sounds like they are loading the entire 4000x4000 image even when they are only retrieving one?

What you are doing is way beyond any of my experience so there's a very high chance I could be totally wrong, but that's my initial thoughts.

avatar image Serath · Mar 25, 2014 at 01:09 AM 0
Share

Uhm, the app is basicly a rating system. User downloads an animation from server and then rates it. He only needs 5 animations per game. But with just one animation downloaded the memory goes wild. (64MB)

avatar image
1

Answer by Bunny83 · Mar 25, 2014 at 12:53 AM

As you can read here and on other pages in the docs Unity only supports a few compressed texture formats. However Android devices only support a small subset of these and if the hardware doesn't support a particular hardware compression it's loaded as uncomressed texture.

If you do the math:

 4000 * 4000 * 4 == 64MB

If you also use mipmapping it's even more.

ps: Are you actually sure that the gif image is loading? In the past and according to the docs only JPG and PNG images can be loaded at runtime via WWW. Maybe that has been changed. Anyways you should also read t$$anonymous$$s page carefully to understand when a loaded texture is actually hardward compressed and when not

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 Julien-Lynge · Mar 25, 2014 at 12:56 AM 0
Share

Also keep in mind that textures that are r/w enabled take even more memory (if I'm remembering correctly).

avatar image Serath · Mar 25, 2014 at 01:10 AM 0
Share

Uhm, actually I'm downloading a .png spritesheet generated from the gif. That's what I meant, but probably expressed myself wrong.

avatar image Bunny83 · Mar 25, 2014 at 10:19 AM 0
Share

Well, ok that makes a bit more sense. What TextureFormat does the texture has before you used LoadImageIntoTexture? because that's the main guide what format the texture will have once loaded. Make sure you created a texture with the desired TextureFormat before you call LoadImageIntoTexture

avatar image Serath · Mar 25, 2014 at 10:38 AM 0
Share

I love you bunny. I set the TextureFormat to DXT1 BEFORE loading it and now it eats doable memory :)

avatar image
0

Answer by DeveshPandey · Mar 31, 2018 at 08:42 PM

Here is a nice plugin, its very easy to use. You can download any small or big file from the web. Must see t$$anonymous$$s plugin

https://www.assetstore.unity3d.com/#!/content/92128?aid=1101l34jr


For more details visit t$$anonymous$$s blog

http://unitydevelopers.blogspot.in/p/blog-page_13.html

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

25 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Spritesheet animation shake/jitter/wobble problem on android. 1 Answer

Animation won't play after marked as legacy 0 Answers

Multiple animation with single button 1 Answer

2d sprite animation issue 2 Answers

Mesh.CreateVBO function in Android 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