Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Stats when running in iPhone

Discussion in 'iOS and tvOS' started by 3dgrinder, Dec 22, 2008.

  1. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    Hi,

    I didn't find any reference or API or any thread in forum about it [correct me if I missed it].

    We can get the VRAM info in Editor and others also, but we can't get any info about how much memory it's eating when running the game in iPhone or how much memory it's freeing when moving one scene to another. This is very important because I need to know my game memory consumption [VRAM and System RAM].

    Please let me know if is there any way?

    Thanks.
     
  2. ReJ

    ReJ

    Unity Technologies

    Joined:
    Nov 1, 2008
    Posts:
    378
    You can use XCode tools to figure it out. Once you're in the XCode with your project loaded, choose Run | Start with Performance Tool | Activity Monitor. You can find information like how much memory or CPU your app takes.
     
  3. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    Thank ReJ. I'm going to hack this out. :)
     
  4. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    When I used Leak Instrument in my application then I found that I'm leaking memory. Then I tried with StartTrooper the example project of Unity. And it's also detect the Memory.

    Here is an attachment of the screen shoot. Can anyone explain why?
     

    Attached Files:

  5. ReJ

    ReJ

    Unity Technologies

    Joined:
    Nov 1, 2008
    Posts:
    378
    Yes, that is known leak inside PhysX. Not fixed yet.
     
  6. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    Good GOD. :(.

    Then how can I release a game with this kind of bugs!!!! Gamer can face unexpected situation anytime.

    Is there anyway to handle this problem? We are close to release a game, now if we face this kind of problem then it is be heart breaking news for us. :(
     
  7. ReJ

    ReJ

    Unity Technologies

    Joined:
    Nov 1, 2008
    Posts:
    378
    That is 16 bytes per frame. Just make sure your app leaves couple of spare megs to the system.

    Other option is not using PhysX - no rigidbodies in your game.
     
  8. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,613
    16 bytes per frame?

    Is this being looked at?
     
  9. cbman

    cbman

    Joined:
    Oct 15, 2007
    Posts:
    23
    16 bytes per frame?? Not using rigidbodies?? Not even triggers work without rigidbodies so it's kind of difficult to get much going without using rigidbodies.
    I have to say I'm getting less and less impressed by the day with using Unity for iPhone dev. Performance is low and with leaks like this it's not very encouraging.

    Don't get me wrong, I love much about Unity but for iPhone dev it's getting closer and closer to a no go..
     
  10. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    cbman, I would like to know what other game engine available for iPhone is even close to Unity? Performance is low? Have you all looked at the Warehouse/occlusion culling demo? It's perhaps the best 3D I've seen on the iphone and it plays very smoothly.

    By my estimate @ 30fps 16 bytes per frame is ~ 1.7MB leaked per hour. That sounds like a lot but how often does a game get played for an hour on an iphone, before getting quit restarted? Also actual framerates will be somewhere between 15 and 30 fps so the number is smaller. This leak is certainly not a showstopper for my game.

    Anyhow, I am curious if setting all rigidbodies to kinematic effectively turns off PhsyX? Probably not. I guess I can load up the tool as described by Rej to try and see.
     
  11. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,602
    the problem is that the leak will remain until you restarted your iphone
    Why do you think do you have to do it regularily.

    But not only Unity is having this issue. That is generally a problem with the iphone os
     
  12. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    dreamora- OK I guess I don't understand. The iphone OS has protected memory because it is based on Darwin/OSX, right? If so then how can leaked memory persist until the device is rebooted? Maybe someone can link to an article or something where this is explained. Thanks
     
  13. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,602
    On the how you will have to ask Apple.
    Fact is that all gamer have to restart their device at least once per day due to low memory problems. Same is normally recommend after installs.
    Until that problem with "blocked RAM" is solved, any other leak that does not kill the game during runtime is not of considerable interest, at least to me as my own leaks are a minimal problem compared to the twice per day restarts I need to do to play simple TD games as they otherwise just "leave" the game back to desktop
     
  14. Randy-Edmonds

    Randy-Edmonds

    Joined:
    Oct 10, 2005
    Posts:
    1,120
    Just curious... Is this something that NVidia is responsible for fixing or can UT somehow correct it?
     
  15. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,602
    UT theoretically, there is no non WinXP / Vista version of physx at all, so no physx bugs on OSX -> none on iphone
     
  16. cbman

    cbman

    Joined:
    Oct 15, 2007
    Posts:
    23
    None that I know of, and there is the dilemma. There are, as pointed out in other posts, some other engines but not with the ease of use Unity offers. And I could of course write it all from scratch and take useful parts from past games I have done but creating an engine takes just as much time as creating a game and I really don't want to spend a year on a game that will sell for $1.99 or so...

    True that is a good demo. But that's the thing, it's a demo, not a game. I can get decent performance with a static structure, that's not the problem. With only about 20 draw calls you are very limited to what you can have going on on the screen. And it seems it's the number of draw calls that really grinds it to a halt. Even with only about 2000 vertices, it comes to a crawl when the draw count goes up.

    And the bloat of the runtime is not a plus either. If it uses about 20 Mb of memory just for the Unity engine stuff when the app runs, that's not exactly good. And getting it on the app store below 10 Mb seems to be pretty much impossible.

    So at this point I really don't know... Looking at some games running on the iPhone, it is possible to do some pretty cool stuff but I don't see how it could be done with Unity in it's current state. I will still try a few more things tho..

    And paying close to 3K just to be able to swap out the Unity splash screen and not really gain anything else does not seem too appealing with all the above taken into account.
     
  17. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Does this PhysX leak apply to Unity Proper too? or just builds for the iPhone/Touch?
     
  18. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    I don't think only 16byte for PhyX. You can try it using Xcode instruments. I found sometimes it's leaking 1024 block also where I have no RB, no Collider and no Phy things, only GUITexture and GUIText.

    Xcode leak gave the info that, memory is leaking from Shader:subclass. So, I'm afraid about release a game with such kind of problem.

    Man, this will ruind all of the future developemnt based on Unity iPhone.
     
  19. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    @seon or anyone: is it possible to leak memory from bad javascript code? I am calling Destroy on unused gameobjects, and calling Application.GarbageCollectUnusedAssets periodically. So other than that, my game's leaking I cannot control, correct?

    @cbman well your position is clear- I can't argue with what you said except
    maybe you should be in the game *engine* business :wink:
     
  20. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Mindlube: Unity does a great job of cleaning up stuff for you, but the areas where you need to be careful are when you are creating instances of materials ect in your own code, like:-

    Code (csharp):
    1. var : mat : Material = new Material();
    You need to make sure you clean up those instances yourself.

    I generally set elements I create myself to null at the end of their use, as a precaution, like WWW instances.
     
  21. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Seon OK thanks for that.
     
  22. UVRadiation

    UVRadiation

    Joined:
    Jul 21, 2008
    Posts:
    183
    When will this be fixed? this is a major major issue for anyone using physics , my game becomes unplayable after ~5 mins.
     
  23. ReJ

    ReJ

    Unity Technologies

    Joined:
    Nov 1, 2008
    Posts:
    378
    PhysX memory leak is fixed and will be released with the next version (I can't give any timelines though).
     
  24. Erik.Hyrkas

    Erik.Hyrkas

    Joined:
    Nov 10, 2008
    Posts:
    14
    Is there a way through script that I can find the available memory and notify users if they are low?

    In an ideal world, if they start the app and have less than say 20 or 25 megabytes, I want them to know.

    Thanks for your time.
     
  25. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Erik... great idea!

    I know UT have more openness planned between cocoa and unity.. they have stated this before, but in terms of planned timeframe... well, only UT know what we will get and when :)
     
  26. Erik.Hyrkas

    Erik.Hyrkas

    Joined:
    Nov 10, 2008
    Posts:
    14
    I think what I wanted was:

    Unfortunately, it isn't implemented. Ah well.
     
  27. championsoftware

    championsoftware

    Joined:
    Jan 8, 2009
    Posts:
    123
    That would be great, I guess for now I'm going to settle with a "Have You Restarded Your Device Today?" message box.

    My current game is perfect initially, it even makes me praise unity, however after some time it becomes unplayable. Testing for leaks to see what was occurring, and reading this form have settled it though. Its pretty much completed too except for this issue, I'll post what I do to fix it because currently I have no other choice.
     
  28. championsoftware

    championsoftware

    Joined:
    Jan 8, 2009
    Posts:
    123
    Fixed it....performance wise. You will still see the leaks, however if you put the rigidbody to sleep before destroying it, it will not hinder the cpu.

    Code (csharp):
    1. rigidbody.Sleep();
    2. Destroy(rigidbody);
    3. Destroy(gameObject);
     
  29. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    I just added a "getMemory" command to the Enhancement Pack. If you don't have my enhancement pack and want to roll your own, the code to get the VM manager info goes like this:

    Code (csharp):
    1.         mach_port_t host_port;
    2.         mach_msg_type_number_t host_size;
    3.         vm_size_t pagesize;
    4.        
    5.         host_port = mach_host_self();
    6.         host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
    7.         host_page_size(host_port, &pagesize);        
    8.        
    9.         vm_statistics_data_t vm_stat;
    10.        
    11.         if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS)
    12.             DebugLog(@"Could not get host_statistics");
    13.        
    14.         natural_t mem_used = (vm_stat.active_count +
    15.                               vm_stat.inactive_count +
    16.                               vm_stat.wire_count) * pagesize;
    17.         natural_t mem_free = vm_stat.free_count * pagesize;
    18.         natural_t mem_total = mem_used + mem_free;
    19.         NSString *s = [NSString stringWithFormat: @"%u,%u,%u", mem_used, mem_free, mem_total];
     
  30. Erik.Hyrkas

    Erik.Hyrkas

    Joined:
    Nov 10, 2008
    Posts:
    14
    Nice Job. I didn't know about your enhancement pack. I'm going to look into it. Thank you.
     
unityunity