Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question GCAlloc occurs when using Addressables in Player

Discussion in 'Addressables' started by ysalpha, Oct 27, 2021.

  1. ysalpha

    ysalpha

    Joined:
    Feb 2, 2017
    Posts:
    52
    Using Addressables in StandAlone builds will cause GCAlloc to occur periodically.

    Specifically, build with StandAlonePlayer (Windows64) and start Profiler.
    After launching the game application, Load some file with Addressables.LoadAssetAsync from AddressablesAsset in local PC.
    then, The process called DiagnosticsEventCollectorSingleton.Update() periodically generates 1.1KB of GCAlloc.
    This is probably done on a VSync-by-VSync basis.
    screenshot.png

    If Addressables.LoadAssetAsync is never called, this GCAlloc will not occur, but once it is called,
    the GCAlloc will continue to occur even if the handle is released.

    Is this a specification or an unexpected behavior?
    Can you at least tell me that?
    Please.
     
  2. ysalpha

    ysalpha

    Joined:
    Feb 2, 2017
    Posts:
    52
  3. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,835
    I'll flag with the team for some insight. Which version of Addressables are you using?
     
  4. ysalpha

    ysalpha

    Joined:
    Feb 2, 2017
    Posts:
    52
    Thanks reply!

    Unity 2020.3.18f1
    Addressables 1.18.16

    If you want, I will submit bug report and attach a reproducible simple project.
     
  5. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    294
    This is caused when Serialising data to be sent from the Player to the Editor in order to display the data in the Event Viewer.

    This should only occur when "Send Profiler Events" is enabled in the AddressableAssetSettings.
    Do you have this set?
     
  6. ysalpha

    ysalpha

    Joined:
    Feb 2, 2017
    Posts:
    52
    No, Disabled this option.
    Also I tried disable to "Log Runtime Exceptions" in the AddressableAssetSettings.
    GC will still occur.
     
  7. ysalpha

    ysalpha

    Joined:
    Feb 2, 2017
    Posts:
    52
    I'm a little confused about the issue.
    Sometimes it happens when I set it to Disable, and sometimes it doesn't happen when I set it back to Enable.
    I'll do some more research.
     
  8. ysalpha

    ysalpha

    Joined:
    Feb 2, 2017
    Posts:
    52
    I have to run the "Build > New Build > Default Build Script" once.
    Send Profiler Events setting does not seem to be applied.
    Is this the intended behavior?

    The reason for this is that I encountered the following situation.
    1. enable "Send Profiler Events", and output Player
    2 GC occurs.
    3. disable "Send Profiler Events" and output Player
    4. GC still occurs
    5. run "Build > New Build > Default Build Script" in Addressables Groups, and output Player
    6. no more GC
     
  9. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    294
    We should only be doing this when Profiler events are enabled. This is a bug.
    I suspect we can make a simple repro easy enough, but if it proves to be something unexpected causing it then I may take you up on your offer :)
    You could also do a bug report if you want to keep updated through the bug report. I will post in this thread once we know a release that will have a fix in however.
     
  10. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    294
    I looked into it and realised your steps:

    The reason for this is that I encountered the following situation.
    1. enable "Send Profiler Events", and output Player
    2 GC occurs.
    3. disable "Send Profiler Events" and output Player
    4. GC still occurs
    5. run "Build > New Build > Default Build Script" in Addressables Groups, and output Player
    6. no more GC


    Yes that is the intended behaviour.
    The settings are saved with the build. So if you are running Use Existing build in editor or in a Player build. Then it will be using the settings from the last build you made.

    In step 3, even if you disable it you need to make a new build for it to be applied to that build.
     
    Last edited: Nov 24, 2021
  11. ysalpha

    ysalpha

    Joined:
    Feb 2, 2017
    Posts:
    52
    I see, thanks!