Sequence of GC and unloading assets in Unity3D












7















Sometimes we need to release useless resources manually in game development.
But I'm not sure which is better between



System.GC.Collect();
Resources.UnloadUnusedAssets();


and



Resources.UnloadUnusedAssets();
System.GC.Collect();


AFAIK, both of them are async operations and there might be no difference.



So my question is...




  1. Are there any difference?

  2. If so, which is better?










share|improve this question























  • UnloadUnusedAsset is async, but actually you can yield to wait until it ends.

    – Heisenbug
    Jul 9 '13 at 9:00
















7















Sometimes we need to release useless resources manually in game development.
But I'm not sure which is better between



System.GC.Collect();
Resources.UnloadUnusedAssets();


and



Resources.UnloadUnusedAssets();
System.GC.Collect();


AFAIK, both of them are async operations and there might be no difference.



So my question is...




  1. Are there any difference?

  2. If so, which is better?










share|improve this question























  • UnloadUnusedAsset is async, but actually you can yield to wait until it ends.

    – Heisenbug
    Jul 9 '13 at 9:00














7












7








7


1






Sometimes we need to release useless resources manually in game development.
But I'm not sure which is better between



System.GC.Collect();
Resources.UnloadUnusedAssets();


and



Resources.UnloadUnusedAssets();
System.GC.Collect();


AFAIK, both of them are async operations and there might be no difference.



So my question is...




  1. Are there any difference?

  2. If so, which is better?










share|improve this question














Sometimes we need to release useless resources manually in game development.
But I'm not sure which is better between



System.GC.Collect();
Resources.UnloadUnusedAssets();


and



Resources.UnloadUnusedAssets();
System.GC.Collect();


AFAIK, both of them are async operations and there might be no difference.



So my question is...




  1. Are there any difference?

  2. If so, which is better?







c# memory-management garbage-collection unity3d






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 9 '13 at 1:30









Joon HongJoon Hong

1,0351022




1,0351022













  • UnloadUnusedAsset is async, but actually you can yield to wait until it ends.

    – Heisenbug
    Jul 9 '13 at 9:00



















  • UnloadUnusedAsset is async, but actually you can yield to wait until it ends.

    – Heisenbug
    Jul 9 '13 at 9:00

















UnloadUnusedAsset is async, but actually you can yield to wait until it ends.

– Heisenbug
Jul 9 '13 at 9:00





UnloadUnusedAsset is async, but actually you can yield to wait until it ends.

– Heisenbug
Jul 9 '13 at 9:00












2 Answers
2






active

oldest

votes


















9














There is no difference between these two kinds.



System.GC.Collect() will tell .Net collector to collect objects which are managed by mono in the managed heap, while Resources.UnloadUnusedAssets deals with assets (textures, sounds and other media) which are put in the native heap. The two method do totally different things, so there is no different which one will be executed first. (As you said, they are both async and you just set a flag to suggest the system it could be a good time to do a collect.)



In fact, it is not so common to call GC collect yourself, except you have a good reason. The GC of system will work in proper time, most of calling for forcing a garbage collect are not so necessary as you think.



If you are wondering more about Unity's memory, you can refer to this blog, which can tell you things in detail.






share|improve this answer

































    0














    As unity guy said UnloadUnusedAssets inside also calls System.GC.Collect(); so if you call UnloadUnusedAssets, you don't need to call System.GC.Collect






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17538570%2fsequence-of-gc-and-unloading-assets-in-unity3d%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      9














      There is no difference between these two kinds.



      System.GC.Collect() will tell .Net collector to collect objects which are managed by mono in the managed heap, while Resources.UnloadUnusedAssets deals with assets (textures, sounds and other media) which are put in the native heap. The two method do totally different things, so there is no different which one will be executed first. (As you said, they are both async and you just set a flag to suggest the system it could be a good time to do a collect.)



      In fact, it is not so common to call GC collect yourself, except you have a good reason. The GC of system will work in proper time, most of calling for forcing a garbage collect are not so necessary as you think.



      If you are wondering more about Unity's memory, you can refer to this blog, which can tell you things in detail.






      share|improve this answer






























        9














        There is no difference between these two kinds.



        System.GC.Collect() will tell .Net collector to collect objects which are managed by mono in the managed heap, while Resources.UnloadUnusedAssets deals with assets (textures, sounds and other media) which are put in the native heap. The two method do totally different things, so there is no different which one will be executed first. (As you said, they are both async and you just set a flag to suggest the system it could be a good time to do a collect.)



        In fact, it is not so common to call GC collect yourself, except you have a good reason. The GC of system will work in proper time, most of calling for forcing a garbage collect are not so necessary as you think.



        If you are wondering more about Unity's memory, you can refer to this blog, which can tell you things in detail.






        share|improve this answer




























          9












          9








          9







          There is no difference between these two kinds.



          System.GC.Collect() will tell .Net collector to collect objects which are managed by mono in the managed heap, while Resources.UnloadUnusedAssets deals with assets (textures, sounds and other media) which are put in the native heap. The two method do totally different things, so there is no different which one will be executed first. (As you said, they are both async and you just set a flag to suggest the system it could be a good time to do a collect.)



          In fact, it is not so common to call GC collect yourself, except you have a good reason. The GC of system will work in proper time, most of calling for forcing a garbage collect are not so necessary as you think.



          If you are wondering more about Unity's memory, you can refer to this blog, which can tell you things in detail.






          share|improve this answer















          There is no difference between these two kinds.



          System.GC.Collect() will tell .Net collector to collect objects which are managed by mono in the managed heap, while Resources.UnloadUnusedAssets deals with assets (textures, sounds and other media) which are put in the native heap. The two method do totally different things, so there is no different which one will be executed first. (As you said, they are both async and you just set a flag to suggest the system it could be a good time to do a collect.)



          In fact, it is not so common to call GC collect yourself, except you have a good reason. The GC of system will work in proper time, most of calling for forcing a garbage collect are not so necessary as you think.



          If you are wondering more about Unity's memory, you can refer to this blog, which can tell you things in detail.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 4 '14 at 6:56

























          answered Jul 9 '13 at 4:32









          onevcatonevcat

          3,8431625




          3,8431625

























              0














              As unity guy said UnloadUnusedAssets inside also calls System.GC.Collect(); so if you call UnloadUnusedAssets, you don't need to call System.GC.Collect






              share|improve this answer




























                0














                As unity guy said UnloadUnusedAssets inside also calls System.GC.Collect(); so if you call UnloadUnusedAssets, you don't need to call System.GC.Collect






                share|improve this answer


























                  0












                  0








                  0







                  As unity guy said UnloadUnusedAssets inside also calls System.GC.Collect(); so if you call UnloadUnusedAssets, you don't need to call System.GC.Collect






                  share|improve this answer













                  As unity guy said UnloadUnusedAssets inside also calls System.GC.Collect(); so if you call UnloadUnusedAssets, you don't need to call System.GC.Collect







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 5:10









                  GeorgiyRGeorgiyR

                  1




                  1






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17538570%2fsequence-of-gc-and-unloading-assets-in-unity3d%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Hercules Kyvelos

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud