Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Standalone Steam Build is eating memory

Discussion in 'Editor & General Support' started by meganinja, Sep 24, 2021.

  1. meganinja

    meganinja

    Joined:
    Apr 2, 2015
    Posts:
    35
    Hello everyone,
    I'm having a problem with a game from the company I work: Steam Players are saying the game crashes every 10-20 minutes. Testing, we found out the RAM usage in the task manager is rising every time the player exits a level and returns to the menu (This is probably the cause of the problem).
    I made a lot of tweaks to the project settings and the general code of the game and when I build the game to a development build with SteamWorks DISABLED the memory usage is normal, is not rising. It keeps around 200-400MB on task manager, on steam it rises 100MB every time the player completes a mission. I'm also using the standard profiler and Memory Profiler for Unity and it's everything normal.
    So I ask you: Could it be something from Steamworks? Maybe if I updated the asset? (I'm using the heathen engineering one). Any tips on what could I check? I already checked the scene transition from the game and it's the same code we used on another game(in which there are no bugs).
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,432
    If you can't see the increase in the memory Profiler package, or only in the Untracked category, chances are it's native plugin code that allocates the memory and has a leak. Since you already tried it without the Steamworks plugin (which I guess is native DLLs?) That does sound like a likely candidate. Did you try and reach out to Steam about this yet?
     
  3. meganinja

    meganinja

    Joined:
    Apr 2, 2015
    Posts:
    35
    Thanks for the tip, Martin.
    My boss and I tried to make a Development Build for steam and fortunately, we were able to link the memory profiler from the editor to the steam build.
    We discovered that the leaderboard showing on the game is using all the memory. Probably because of all the player icons pictures. Also, it's possible that every time we complete a mission on the game, the leaderboard loads all icons again and doesn't unload the others:
    But this shouldn't be a problem because we have another game on steam using the same logic and there is no memory problem with the leaderboard. I'm looking into this right now, could it be a bug on the Steamworks API?
    PS: I'm not very used to the meaning of "Native Plugin Code", could you explain it a little better?
    EDIT: All those little cubes are Texture2D ("Native Object") with NO name
    upload_2021-9-24_19-14-34.png upload_2021-9-24_19-14-52.png
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,432
    Native plugin code would be anything you have in your project as a .dll file and might be storing in a Plugins folder, though asmdefs have made that folder somewhat redundant.

    The no name part is likely down to thoae images being created at runtime via a download and then the Texture2D objects are not getting their .name set. You can search your scrips for all usages of Texture2D, especially for it's creation and check that it gets a name set in there. (I'm assuming they don't have a name in the table either and are bigger that a few bytes and still have native memory attached to them, otherwise they are "leaked Managed Shell objects", i.e. just the scripting instance, because something is still keeping a reference to them.
     
  5. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,432
    It could be. I don't have enough info or insight into that API to say so definitively though.
    Are they still referenced? If not you could try to manually unload them with Resources.UnloadUnusedAssets.
     
  6. meganinja

    meganinja

    Joined:
    Apr 2, 2015
    Posts:
    35
    Thank you MartinTilo. I've solved the problem (finally). I was able to unload the Texture2Ds from the leaderboard!
    Sorry for taking too long to answer, but at least everything is working now!
     
    MartinTilo likes this.
  7. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,432
    No worries on the delay. I'm happy I was able to help :)

    If you're up for it, I'd be happy to hear some feedback on your profiling & debugging experience, so we can improve it:

    Did any bit of the tools help you isolate it? How did you track it down and do you have any ideas how that could've been made easier?
     
  8. meganinja

    meganinja

    Joined:
    Apr 2, 2015
    Posts:
    35
    It was very easy to identify the problem once I used the Memory Profiler Package. It was so helpful.
    The only problem I had was that it was really hard to analyze on the Editor since memory usage is different on a standalone build and in the editor.
     
  9. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,432
    That's good to hear, thank you :)

    That is very true. We've added an item to the Top Issues section in the Memory Profiler v 0.4 to alert to that potential issue for Editor captures due to how commonly it trips people up. We've also done quite some work on making it easier to connect to build Players in 2021.2, and will continue to improve that core bit of the profiling workflow.

    Btw, for things that are held in memory by other objects or reasons we are actively working on making those reasons and reference chains more obvious in the next minor version of the package. That should hopefully make it even easier :)