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 alkibabs · Jan 04, 2012 at 01:10 PM · texturesmemory leakwww.texture

App crashing on Ipad - suspected memory leak.

Hi, its late, so please excuse any typos.

I've been stuck on this problem for about 6 hrs and I am running out of ideas. Have been on the unity answers forum all night, trying to find out whether this is an issue...

Essentially I am dynamically/programmatically creating 54 planes that are essentially square tiles. They are children of a parent object and inherit the position and rotation from the parent object. Then, using a simple loop, I populate each plane/tile with a dynamic texture using the WWW class to download the image and load it into the plane's main texture. Source image for each tile is 128*128 PNG. (about 15-20k, not huge...) Works well, and can rotate the parent object and child planes follow suit... all good.

BUT!!!

I can then try repopulate the SAME tiles (no destroying, just reassigning new textures to them) a few times, before it consistently crashes out after about the 3rd or 4th time of loading the new set of images, but when running in the editor it seems to slow down more and more each time I repopulate the tiles with new images (however it can be done about 50 times in the editor, rather than just the measly 3 times on the device.

The obvious things I am doing are:

Destroying the WWW object each time I download the image. Setting any variables to Null and destroying what I can after each time the tiles are updated. Using the same tiles, and not destroying and recreating, to save potential memory leaks. Doing a Garbage collection after each reload of the images.

Like I said, I have spent many hours trying to resolve this -- I can provide code samples, but I wanted more to ask whether there are any "quirks" that anyone is aware of related to this?

I am just reloading new texture images, to existing planes, from the local file storage, and all of the images are the same size, (about 15k each!!) and just looping through the 54 planes and setting the main texture to the www.texture of the downloaded PNG.

I have tried also destroying the planes, and recreating, and the same problem occurs. 3 or 4 times of loading sets of images, and it just crashes out --- works fine in the editor.

I guess I dont understand, if I am essentially just replacing the existing textures, with new ones that are comparable in size, it should not increase the memory/resource usage, I wouldn't have thought? But it appears to be?

Should i be doing something to the main texture of the plane before asssigning a new texture image?

Any ideas? Thankyou in advance.

I'm using Unity Iphone edition

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
2

Answer by alkibabs · Jan 06, 2012 at 01:07 AM

Hi, in case anyone else had this issue - I found a solution:

It seems that using the www.texture creates a new texture in memory each time you call it, and does not get destroyed when you destroy the WWW object after downloading the image. So the RAM was getting filled up with new textures despite destroying all the objects used to create the texture,

So, I ended up creating a planeObjscript.js script file, containing the below

public var t_dynamic_tex : Texture2D = null;

and attaching the script to each plane using addcomponent.

When first dynamically creating the planes and adding the script above, I set t_dynamic_tex = new Texture2D(128, 128); (only the first time, never again)

Then I load the image from the file using something like code below: (looping 54 times, changing plane_x to 1,2,3,4,5 etc)

var planeObj : planeObjscript = GameObject.Find("plane_x").GetComponent(planeObjscript); imgbyt=null; imgbyt = System.IO.File.ReadAllBytes(Application.persistentDataPath + "/" + imagename); planeObj.t_dynamic_tex.LoadImage(imgbyt); planeObj.renderer.material.mainTexture = planeObj.t_dynamic_tex; imgbyt=null;

It uses the SAME Texture2D for each of the 54 planes each time, and memory usage does not increase. Runs very quickly too..

A dramatic increase in performance from using the www.texture, I can literally change the textures as many times as I want, and to date, it has not crashed on the Ipad once.

Hope this helps someone.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Resources vs Asset Bundles vs file:// 0 Answers

Loading PSD files at runtime with WWW 1 Answer

GLES3 Error: Post Processing 0 Answers

What's the easiest way to fix this streched texture? 1 Answer

In Unity 2017.3.1 Getting Error regarding Splat texture 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