p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   Garbage Collector -- Is it working? (http://p2p.wrox.com/showthread.php?t=59309)

vishwjeet June 21st, 2007 09:22 AM

Garbage Collector -- Is it working?
 
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

vishwjeet June 22nd, 2007 05:51 AM

Hey..I posted same query in beginners section too..but didnt got any solution.


- Vishu


All times are GMT -4. The time now is 05:06 AM.

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