Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Object Memory Space

Object Memory Space

Scheduled Pinned Locked Moved .NET (Core and Framework)
performancequestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CBoland
    wrote on last edited by
    #1

    Does anyone know what factors affect the memory size an object will consume by simply creating a new instance? I know that member-level value-types will consume memory respective of their data type (Int32 consumes 4 bytes, etc.). What about code? Does a class that contains no member variables, but 2000 lines of code consume any memory by simply instantiating a new one?

    D A 2 Replies Last reply
    0
    • C CBoland

      Does anyone know what factors affect the memory size an object will consume by simply creating a new instance? I know that member-level value-types will consume memory respective of their data type (Int32 consumes 4 bytes, etc.). What about code? Does a class that contains no member variables, but 2000 lines of code consume any memory by simply instantiating a new one?

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #2

      CBoland wrote: Does anyone know what factors affect the memory size an object will consume by simply creating a new instance? I know that member-level value-types will consume memory respective of their data type (Int32 consumes 4 bytes, etc.). What about code? Does a class that contains no member variables, but 2000 lines of code consume any memory by simply instantiating a new one? Generally, no. Since .NET is garbage collected, an instance of a class needs some information for garbage collection and Reflection. IIRC, any Object instance on .NET takes 16 bytes of memory. Another common source of "hidden" memory consumption on OOP environments are virtual methods. ORACLE One Real A$#h%le Called Lary Ellison

      1 Reply Last reply
      0
      • C CBoland

        Does anyone know what factors affect the memory size an object will consume by simply creating a new instance? I know that member-level value-types will consume memory respective of their data type (Int32 consumes 4 bytes, etc.). What about code? Does a class that contains no member variables, but 2000 lines of code consume any memory by simply instantiating a new one?

        A Offline
        A Offline
        Aravinthan 0
        wrote on last edited by
        #3

        Code shouldnt affect memory.. but if you have declared any virtual functions or derived from some some asbtract base class.. it will as vtable does require some space.. And any static variables also consume.. but only once.. aravinthan


        Visit me:
        http://www2.domaindlx.com/earavi/
        When you know something.. its meant to share with others :-) for otherwise that knowledge has no worth:-)
        mail me:
        aravinthan@rediffmail.com


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups