• 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 busychild · Jun 21, 2012 at 06:52 PM · iostexturetexture2dmemorymemory-leak

Loading external Image as Texture2D increases memory consumption dramatically on iOS

Hi folks,

i've a weird problem with loading external images as textures because the memory consumption increases unacceptable .

I'm currently loading about 100 images:

 IEnumerator loadTexture(string url, GameObject cube) {

     _textureURL = "file://" + Application.dataPath + "/../../Documents/webcontent/app/media/" + url; 
     _www = new WWW(_textureURL);
     yield return _www;
     _tempTexture = new Texture2D(256, 256);
     _www.LoadImageIntoTexture(_tempTexture);
     cube.renderer.material.mainTexture = _tempTexture;
 }


The whole images are using approximately 2-3MB of disc space but if i run the profiler i can see that these images are using more than 200MB of memory! What's going on there?

I also tried to initialize the Texture2D with different texture formats but this is not working as well just as loading the assets via the "System.IO.File.ReadAllBytes"-method and then load it on the texture (_tempTexture.LoadImage(textureBytes).

Thanks in advance for your help!

Comment
Add comment · Show 12
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 whydoidoit · Jun 21, 2012 at 06:56 PM 0
Share

Are your images power of 2 dimensions?

avatar image busychild · Jun 21, 2012 at 06:59 PM 0
Share

No, but i've tried it with an image which is (loaded these image 100-times) - the result was the same but just in case i will give it one more try!

avatar image whydoidoit · Jun 21, 2012 at 07:02 PM 1
Share

If they aren't power of two dimensions then it will get much bigger due to buffer allocations. Bear in mind images in memory are always massively bigger than jpg or png files as those are compressed file formats.

avatar image busychild · Jun 21, 2012 at 07:09 PM 0
Share

Ok thanks! I've tried it but it turns out that a 512px x 512px .png image increases the memory much more than the other images. Here are the results from the profile:

  1. Before loading the external images: http://www.equalion.de/help/before.jpg

  2. After loading the external images: http://www.equalion.de/help/after.jpg

BTW: The .png image is using 101kb of disc space and i know that uncompressed images are getting bigger in memory than compressed ones but i can't believe that it increases from 10$$anonymous$$B disc space (100 * 101kb) to more than 400$$anonymous$$B in memory...

avatar image whydoidoit · Jun 21, 2012 at 08:40 PM 0
Share

No the in memory size of your images is around 103$$anonymous$$B as a guess - one 512x512 image takes just over 1$$anonymous$$B of ram. The rest will be buffers etc used to import the image I imagine (it really is very costly). However, just because the OS profiler says you have that much memory does not mean that the application is using it - it can be allocated but not garbage collected yet.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I load textures at runtime with a smaller memory footprint? 1 Answer

Textures/Atlases and memory management 0 Answers

Bug - Texture "corrupted" after sending on server with MultipartformDataSection, only on iOS 1 Answer

Unloading asset bundles doesn't clear memory on iOS 1 Answer

the texture appear rubbish 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges