ASP.NET Core is a powerful, modern framework for building web applications

Garbage Collection 

I want to explain the Garbage Collection concept in C#.

Purpose: The definition of Garbage Collection is it will clear the memory space, the type of memory we can call the expired objects that are no longer needed.
 
Advantages

  1. Automatic memory management. 
  2. Release managed and unmanaged resources and resource cleanup.
  3. Reduce the errors.s
  4. Prevent the memory leaks.
  5. Optimize the performance.

I would like to explain the Generations approach:

  1. GEN 0: Generation 0 represents short-lived objects, which are temporary objects, such as those used in methods, LINQ queries, etc.
    If objects survive in Gen 0, they are moved to Gen 1. This generation is also referred to as the youngest generation.
  2. GEN 1: Generation 1 acts as an intermediate stage between short-lived (Gen 0) and long-lived (Gen 2) objects.
    Examples include objects passed between methods, temporary configuration data, or state information that is reused across multiple operations.
  3. GEN 2: Generation 2 represents the long-lived objects. These objects have survived garbage collection in both GEN-0 and GEN-1.
    Examples include database connection strings, dependency injection containers, singleton objects, etc. This generation represents the oldest generation in the garbage collection hierarchy.

Using Finalization and Dispose

Finalizers (~ClassName()): Allow objects to clean up resources before being collected. However, finalizers delay GC, so it's better to use IDisposable for resource management.

protected void Page_Load(object sender, EventArgs e)
{
    this.Page.MaintainScrollPositionOnPostBack = false;

    if (!IsPostBack)
    {
        if (BindArticleInfo())
        {
            hddRawUrl.Value = HiddenRawUrl.Value = Request.RawUrl;
            hiddenFieldReturnUrl.Value = CommonFunctions.LoginCheckReturnUrl(Request.RawUrl);
            hddArticleID.Value = ArticleId;
            MembershipServices membershipServices = new MembershipServices();
            DataTable CheckUserMembership = new DataTable();
            if (!object.Equals(Session["UserId"], null))
            {
                CheckUserMembership = membershipServices.CheckUserMembership((Session["UserId"].ToString()));
            }
            else
            {
                non_member.Visible = true;
                non_member.Attributes.Remove("onclick");
                string currentPathAndQuery = Request.Url.PathAndQuery;
                string encodedUrl = Server.UrlEncode(currentPathAndQuery);
                non_member.HRef = CommonFunctions.LoginCheckReturnUrl(encodedUrl);
            }
            if (CommonFunctions.ValidateDataTable(CheckUserMembership))
            {
                var MembershipExpire = CheckUserMembership.Rows[0]["MembershipExpire"].ToString();
                if (DateTime.Parse(MembershipExpire) > DateTime.Now.Date)
                {
                    download_article.Visible = true;
                    non_member.Visible = false;
                }
                else
                {
                    non_member.Visible = true;
                    download_article.Visible = false;
                }
            }
            else if (Page.User.IsInRole("A") || Page.User.IsInRole("E"))
            {
                download_article.Visible = true;
                non_member.Visible = false;
            }
            else
            {
                non_member.Visible = true;
                download_article.Visible = false;
            }
            ManageControls();
            //string checkStauts = ConfigurationManager.AppSettings["popup"].ToString();
            //if (checkStauts != "none")
            //{
            //    if (popupBox.Count > 0)
            //    {
            //        Random random = new Random();
            //        int index = random.Next(popupBox.Count);
            //        switch (popupBox[index].Type)
            //        {
            //            case "Certification":
            //                EbookPopup.InnerHtml = "<div class=\"div-Skill\">\r\n<div class=\"skill-img\">\r\n<img id=\"img\" runat=\"server\" src=" + popupBox[index].ImageURL + ">\r\n</div>\r\n<div class=\"skill-wrap\">\r\n<div class=\"skill-name\">\r\nTest your <span id=\"skillname\" runat=\"server\">" + popupBox[index].Title.ToString() + "</span> skills certifications!\r\n</div>\r\n</div>\r\n</div>\r\n<a href=" + popupBox[index].SiteUrl.ToString() + "?utm_campaign=popup&utm_medium=csharpcorner&utm_source=certification" + " id=\"skillLink\" class=\"btn-success\" runat=\"server\">\r\nGet Started!\r\n</a>";
            //                break;
            //            case "Ebook":
            //                EbookPopup.InnerHtml = "<div class= \"eBook-wrap\">\r\n <div class=\"e-book-img\">\r\n<a id=\"EbookPopupImageUrl\" runat=\"server\" href=" + popupBox[index].SiteUrl.ToString() + "?utm_campaign=popup&utm_medium=csharpcorner&utm_source=ebook" + " aria-label=\"ebook url\">\r\n<img id=\"EbookPopupImage\" alt=\"CSharp.com Ebook\" runat=\"server\" src=" + HttpUtility.UrlDecode(popupBox[index].ImageURL.ToString()) + "></a>\r\n</div>\r\n<div class=\"e-book-title\">\r\n<p class=\"e-book-title\" id=\"EbookTitles\" runat=\"server\">" + popupBox[index].Title.ToString() + "</p>\r\n<a href=" + popupBox[index].SiteUrl.ToString() + "?utm_campaign=popup&utm_medium=csharpcorner&utm_source=ebook" + " id=\"EbookLink\" runat=\"server\" class=\"btn-primary\">\r\nDownload Now!\r\n</a>\r\n </div>\r\n</div>";
            //                break;
            //            case "Learn":
            //                EbookPopup.InnerHtml = "<div class=\"div-learn\">\r\n<div class=\"skill-img\">\r\n<img id=\"img1\" runat=\"server\" src=" + popupBox[index].ImageURL + " >\r\n</div>\r\n<div class=\"skill-wrap\">\r\n<div class=\"skill-name\">\r\n" + popupBox[index].Title.ToString() + "\r\n</div>\r\n</div>\r\n</div>\r\n<a href=" + popupBox[index].SiteUrl.ToString() + "?utm_campaign=popup&utm_medium=csharpcorner&utm_source=learn" + " id=\"A1\" class=\"btn-primary\" runat=\"server\">\r\nStart Learning\r\n</a>";
            //                break;

            //        }
            //    }
            //    else
            //    {
            //        EbookPopup.Visible = false;
            //    }

            //}
            //else
            //{
            //    popup.Visible = false;
            //}
        }
        else
        {
            Response.Redirect(ResolveUrl(ConfigurationManager.AppSettings["PageNotFound"]));
        }

        var pageUrl = (ConfigurationManager.AppSettings["SiteUrl"] + Request.RawUrl).ToLower();
        CommonFunctions.AddMetaTag("Title", Page.Title, Page, 4);
        CommonFunctions.AddOgUrlAndTitle(pageUrl, Page.Title, HiddenContentShortDescription.Value.Trim(), Page, "Articles");




    }
}
C#

 

Up Next
    Ebook Download
    View all
    Learn
    View all
    GE HealthCare will never ask for payment to process documents, refer you to a third party to process