Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

C# Memory Allocating and Releasing

$
0
0

In the following code snippet :

 

private void btnCalc_Click(object sender, EventArgs e)
{
  bool flag;
  int year;
  int leap;

  clsDates myDate = new clsDates();

  .

  .

  .

}

The first line of code after the variable declarations creates a new class of type clsDates.  Initially, I was concerned that a new class would be created every time the Calc_Click button is clicked, eating up memory.  Now I am wondering if the memory obtained on the creation of the new class is "released" after the function is completed.  My question is:  Which way does it work??  Is this bad programming technique that eats up memory everytime the button is clicked or is this good technique as the memory containing the class is "freed" upon completion of the function.

I don't want to get into a discussion on how or when the garbage collector runs or what it does.  I am just trying to wrap my brain around how the memory is allocated and freed for the garbage collector to handle.

Thanks for reading!


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>