ReadingNotes

Classes & Memory Management

Introduction to classes

Constructors (C# programming guide)

Properties (C# Programming Guide)

Remember, properties provide a way to encapsulate data and control access to it. They offer more control and flexibility compared to directly exposing fields as public members. If you have any specific questions or need further clarification on any of these topics, feel free to ask!

Properties Questions

  1. What’s the difference between a static and an instance constructor?
  1. How does the use of a static constructor differ from setting properties/values?

A static constructor initializes static fields or properties of a class only once when the class is loaded into memory. This differs from setting properties or values, which is done for each instance of the class separately. Static constructors cannot be called explicitly, while setting properties or values can be done at any time.

stack and heap

The Stack is more or less responsible for keeping track of what’s executing in our code (or what’s been “called”). The Heap is more or less responsible for keeping track of our objects(our data..well most of it).

4 main types of things we going to be put in the Stack and heap are: Value Types, Reference Types, Pointers, and Instructions.

In C#, all the “things” declared with the following list of type declarations are Value types

All the “things” declared with the types in this list are Reference types (and inherit from System.Object… except, of course, for object which is the System.Object object)

Questions stack and heap

  1. Knowing about the stack and the heap, I might consider the following strategies to make more efficient use of memory in my projects:

Avoid creating too many unnecessary objects that are stored on the heap. I would try to reuse objects whenever possible rather than creating new ones. Consider using value types instead of reference types where appropriate. Value types are stored on the stack and are more efficient in terms of memory usage.

Fundamentals of garbage collection

Questions on Garbage collection

  1. Compare “Garbage Collection” in C# with the lifecycle of normal household items.

Garbage collection in C# to the lifecycle of household items, stating that both involve managing and disposing of unwanted or unneeded items. Garbage collection involves the automatic removal of unused objects from memory, improving performance. Similarly, household items are acquired, used, and eventually disposed of in a responsible manner. Both garbage collection and households need periodic management to ensure optimal performance and a clean, organized living space.

Things i want to know more about