Re: garbage collection of remote objects
From: Mr071 (_at_)
Date: 05/08/04
- Next message: Mr071: "Re: list of currently registered objects"
- Previous message: Lostinet[MS DOTNET MVP]: "Re: Verify RemotingServices.Connect Proxy object"
- In reply to: Sunny: "Re: garbage collection of remote objects"
- Next in thread: Sunny: "Re: garbage collection of remote objects"
- Reply: Sunny: "Re: garbage collection of remote objects"
- Reply: Orlin Popov: "Re: garbage collection of remote objects"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 8 May 2004 17:45:47 -0400
I agree with GC == not_predictable. However, it seems like it *never*
releases these object. In previous version of this code I called
GC.Collect() and GC.WaitForPendingFinalizers() at different points in
implementation. It did nothing.
Has anyone ever "seen" a MarshalByRefObject disposed "naturally" before app
or appdomain starts shutting down?
Mr071
"Sunny" <sunnyask@icebergwireless.com> wrote in message
news:eVDh7bENEHA.3016@tk2msftngp13.phx.gbl...
> Hi,
> GC is not predictable. You do not know when and how it will happen. Try
> using:
> GC.Collect();
> GC.WaitForPendingFinalizers();
>
>
> Sunny
>
> In article <O#OB8W9MEHA.1312@TK2MSFTNGP12.phx.gbl>, "Mr071" <sanins @
> _no_spam_ hotmail.com> says...
> > 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?
> >
> >
- Next message: Mr071: "Re: list of currently registered objects"
- Previous message: Lostinet[MS DOTNET MVP]: "Re: Verify RemotingServices.Connect Proxy object"
- In reply to: Sunny: "Re: garbage collection of remote objects"
- Next in thread: Sunny: "Re: garbage collection of remote objects"
- Reply: Sunny: "Re: garbage collection of remote objects"
- Reply: Orlin Popov: "Re: garbage collection of remote objects"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|