Object lifetime in C#

  • References to global objects (though these are not allowed in C#, CIL code does permit allocation of global objects)
  • References to any static objects/static fields
  • References to local objects within an application’s codebase
  • References to object parameters passed into a method
  • References to objects waiting to be finalized (described later in this chapter)
  • Any CPU register that references an object
  • Generation 0: Identifies a newly allocated object that has never been marked for collection
  • Generation 1: Identifies an object that has survived a garbage collection (i.e., it was marked for collection but was not removed because the sufficient heap space was acquired)
  • Generation 2: Identifies an object that has survived more than one sweep of the garbage collector

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Avinash Karat

Avinash Karat

Working professionally as a full stack .Net developer . Also have a keen interest in personal productivity, meditation&personal finance. Here to share things.