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 Lemon · Mar 12, 2011 at 05:08 AM · instantiatecrashmemoryprofileripad

Instantiate fails on iPad. How can I debug memory allocation errors?

Currently my iPad app crashes in the middle of calling Instantiate. The line it fails on is this exact line (I have debug output before and after it). I can't replicate the crash on my mac in the editor.

Texture2D restore = UnityEngine.Object.Instantiate(undoData[currentIndex-1]) as Texture2D;

where undoData is an array of Texture2D objects and undoData[currentIndex-1] is not null (I've checked)

I initially thought that this could be to do with memory. I ran the internally iPad profiler which gave:

iPhone Unity internal profiler stats:
cpu-player>    min:  7.7   max: 70.8   avg: 16.6
cpu-ogles-drv> min:  1.5   max:  3.0   avg:  1.8
cpu-waits-gpu> min:  0.2   max:  0.4   avg:  0.2
 msaa-resolve> min:  0.0   max:  0.0   avg:  0.0
cpu-present>   min:  0.5   max:  3.1   avg:  1.2
frametime>     min: 30.3   max: 78.4   avg: 37.7
draw-call #>   min:  28    max:  28    avg:  28     | batched:     0
tris #>        min:  1566  max:  1566  avg:  1566   | batched:     0
verts #>       min:  3140  max:  3140  avg:  3140   | batched:     0
player-detail> physx:  1.0 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.0 render:  1.8 fixed-update-count: 1 .. 4
mono-scripts>  update: 13.2   fixedUpdate:  0.0 coroutines:  0.1 
mono-memory>   used heap: 3194880 allocated heap: 27750400  max number of collections: 0 collection total duration:  0.0
----------------------------------------

As you can see there is plenty of allocated space in the heap.

Is it possible that I have run out of video memory? Is there a way to check this? How could I go about debugging this problem?

Edit:

It definetly is a memory warning. I've been able to find a

WARNING -> applicationDidReceiveMemoryWarning()

message hidden further up above the profiler. This suggests that the used heap / allocated heap values don't reflect the full story and can't really be trusted :/

Update:

Problem solved - but why?

This problem was indeed caused by a memory leak. When replacing the texture on the material, I did not destroy the previous texture, which resulted in the replaced texture remaining in memory.

By calling:

Destroy( renderer.material.GetTexture ("_Texture2") );

before the replacement of the texture:

renderer.material.SetTexture("_Texture2", newTex);

Note that a memory warning was not always produced by the internal profiler.

I still don't understand why this occurs? Shouldn't the memory be collected by the garbage collecter once there are no references pointing to the old texture? Forcing GC.Collect() doesn't work either.

Comment
Add comment · Show 1
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 Bunny83 · Mar 12, 2011 at 05:54 AM 0
Share

I removed my comments, finally i think that should work and i've no idea except what you've already mentioned...

1 Reply

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

Answer by Statement · Mar 13, 2011 at 01:30 AM

Shouldn't the memory be collected by the garbage collecter once there are no references pointing to the old texture?

Unity could internally keep a reference to the texture, so there is no guarantee.

I don't know iPads architecture but it is possible textures were maintained in special texture memory (video memory) that was running out, which might not be part of the heap/stack memory.

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

No one has followed this question yet.

Related Questions

unexpected massive memory allocation on iOS while loading maps 1 Answer

[iOS Memory Question] At ~35MB of memory on a heavily multitasked iPhone4/iPad we are getting suspend-crashes after lowmemory warnings. Is there anything we can do? 1 Answer

Crash during Level Load on iPad 1 Answer

Code freezes Unity and I don't know how to fix 1 Answer

Profiler showing wrong memory info? 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