garbage collection of remote objects
From: Mr071 (_at_)
Date: 05/07/04
- Next message: Sunny: "Re: Remoting a Hashtable contain a Hashtable ?"
- Previous message: A. Burch: "Remoting a Hashtable contain a Hashtable ?"
- Next in thread: Sunny: "Re: garbage collection of remote objects"
- Reply: Sunny: "Re: garbage collection of remote objects"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 6 May 2004 21:50:56 -0400
Despite everything that has been written about how LifetimeServiceManager on
the remote server eventually "release" the reference to the object so that
it can be garbage collected it *never* happens. I am not sure what needs to
be done in this code to make it release the remoted reference:
using System;
using System.Threading;
using System.Runtime.Remoting.Lifetime;
public interface IMy
{
bool isAlive { get; }
}
public class Test
{
public static void Main()
{
try
{
LifetimeServices.LeaseManagerPollTime = TimeSpan.FromSeconds(2);
DataClass _x = new DataClass();
_x.kill();
_x = null;
AppDomain _d = AppDomain.CreateDomain("new domain");
DataClass _c = (DataClass)_d.CreateInstance("test",
"DataClass").Unwrap();
ILease _l = (ILease)_c.GetLifetimeService();
Console.WriteLine(_l.GetType().FullName);
Console.Write("\npress ENTER to kill object");
Console.ReadLine();
_c.kill();
Console.Write("\npress ENTER to induce GC");
Console.ReadLine();
Console.WriteLine("Abusing memory");
int x = 150;
byte[][] b = new byte[x][];
for (int i = 0; i < x; i++)
{
b[i] = new byte[1024 * 1024];
for (int j = 0; j < 1024 * 1024; j++)
b[i][j] = (byte)(j % 255);
}
for (int i = 0; i < x; i++)
Console.Write("{0} ", b[i][0]);
Console.Write("press ENTER to end");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
public class DataClass : MarshalByRefObject, IMy
{
private bool theFlag = true;
public void doWork() { Console.WriteLine("working"); }
public override object InitializeLifetimeService()
{
ILease lease = (ILease)base.InitializeLifetimeService();
if (lease.CurrentState == LeaseState.Initial)
{
lease.InitialLeaseTime = TimeSpan.FromSeconds(1);
lease.SponsorshipTimeout = TimeSpan.Zero;
lease.RenewOnCallTime = TimeSpan.Zero;
}
lease.Register(new MySponsor(this));
return lease;
}
public bool isAlive { get { return theFlag; }}
public void kill() { theFlag = false; }
~DataClass()
{
Console.WriteLine("Disposing");
}
}
public class MySponsor : MarshalByRefObject, ISponsor
{
private IMy my;
public MySponsor(IMy my)
{
this.my = my;
}
public TimeSpan Renewal(ILease lease)
{
Console.WriteLine("\nContacted...");
Console.WriteLine(my.isAlive);
if (my.isAlive)
return TimeSpan.FromSeconds(2);
else
return TimeSpan.Zero;
}
}
Any ideas?
-- Mr 071, MCSD.NET, MCAD.NET ----------------------------------------------- "...the rank and file are usually much more primitive than we imagine. Propaganda must therefore always be essentially simple and repetitious." -Joseph Goebbels, Nazi Propaganda Minister, aka Rush Limbaugh, aka Bill O'Reilly, aka FOX News Editors.
- Next message: Sunny: "Re: Remoting a Hashtable contain a Hashtable ?"
- Previous message: A. Burch: "Remoting a Hashtable contain a Hashtable ?"
- Next in thread: Sunny: "Re: garbage collection of remote objects"
- Reply: Sunny: "Re: garbage collection of remote objects"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|