Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2007, 03:18 PM
Authorized User
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vishwjeet
Default Garbage Collection - Finalizer is never invoked

Hey ppl, I am trying the following code to see what is the effect of GC.Collect on the code. As per

http://www.andymcm.com/dotnetfaq.htm#5.9

if GC.Collect is called, finalizer should be called for the object ob1. If GC.COllect is commented ...its unpredictable.

But for me this doesnt seems to be working. Any ideas?

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class GarbageCollectionDemo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        clsTempObject ob1 = new clsTempObject();
        ob1.Use();
    }
}

internal class clsTempObject
{
    //int[] arr = new int[1];
    int arr;
    bool finalizerFlag;

    internal void Use()
    {
        arr = 10;
        finalizerFlag = false;
        //arr[0] = 10;
        staticUse(arr);
    }

    internal static void staticUse(int arr)
    {
        GC.Collect();
        ++arr;
    }

    ~clsTempObject()
    {
        finalizerFlag = true;
        arr = 99;
    }
}

- Vishu
__________________
- Vishu
 
Old June 22nd, 2007, 05:33 AM
Authorized User
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vishwjeet
Default

No replies????

- Vishu





Similar Threads
Thread Thread Starter Forum Replies Last Post
Garbage Collection azizur123 .NET Framework 2.0 1 February 3rd, 2008 11:16 AM
garbage collection generalization tapan General .NET 2 April 27th, 2007 07:13 AM
Garbage Collection... kk_katepally General .NET 1 December 21st, 2004 04:18 AM
garbage collection can't work? gkb Pro PHP 1 July 31st, 2003 02:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.