Search Unity

Libraries that I am not using

Discussion in 'Scripting' started by xavicarosilvente, Dec 3, 2020.

  1. xavicarosilvente

    xavicarosilvente

    Joined:
    Nov 8, 2018
    Posts:
    8
    upload_2020-12-3_17-12-15.png
    Hello, I would like to know what the libraries consume, if I am not using them, are they stealing part of the memory?
    I am very curious especially to optimize my project as much as possible thanks!
     
  2. Ray_Sovranti

    Ray_Sovranti

    Joined:
    Oct 28, 2020
    Posts:
    172
    "using" statements are namespaces, not libraries, and they are nothing except convenient name references for C#. e.g. "using UnityEngine;" allows you to write MonoBehaviour instead of UnityEngine.MonoBehaviour. If you're not using them, the using statements cost no resources whatsoever, they only use space in your C# file and at worst may clutter up your autocomplete/Intellisense results in your IDE.
     
    Bunny83 likes this.
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    If you're not using them, they will be ignored by the compiler. It will have no effect on your final game.

    I would personally consider it best practice to remove them however, simply to reduce clutter.
     
    Bunny83 and Joe-Censored like this.
  4. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    4,006
    Absolutely. Though it's a good time to think about which of the often used types resides in which namespaces. Because when you later decide to use a generic List and you removed the "System.Collections.Generic" namespace you will get an error.

    However at the same time, when using Visual Studio, you should get familiar with the IDE. Because when you use a class from a namespace you haven't (yet) "imported" through a using statement, VS can add it for you. Though you have to write out the classname correctly for that feature. Anyways, always look out for the "quick fix" tooltip at a line with an error.
     
  5. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    Those libraries are not stealing your memory, they occupy it (as long as your application runs). When you build your application you will find some .dll files in your apllications "managed" folder. Those contain your own code and code Unity requires to run, code from 3rd parties (Asset Store stuff) and so on. Those libraries ARE loaded with your application but I'm not sure if they are completely present the whole runtime or if they are loaded on demand. Especially with windows dlls some black vodoo magic is happening which sometimes leads to weird bugs ;).
    So those dlls of Unity stuff and net/mono runtime (your example with collections.generic) are also present when you don't inlcude them into your own codefiles. But should you care about it? NO. They are loaded into memory in binary form as machine instructions (the IL code is compiled to the target platform). And every method is only loaded once no matter how often it runs in the end. There is happening some other magic with pointers. So when you REALLY need to optimize your game (what I doubt) this is NOT the place to do it. The usual path when you EXPERIENCE performance problems is to profile, optimize, profile again and keep the changes only when they actually improve performance. If you do it differently than that chances are you are doing it wrong.