Singleton object garbage collection

Hello:

I have a remoting singleton object published by a windows service host.

This service manipulates two xml files according to remoting clients instructions. This instructions are provided using the remote object.

After each call, I can see in performance counters (CLR Memory) that the remoting Windows service host takes CLR memory during each method call.

My object leassing time is infinite:

1. Do I have to consider anythink special in this scenary for garbage collection

2. If I set a non infinite time as lease time... Is there any strategy to stand up remoting object automatically after lease time expired .

Thanks for all.

Carlos Perez Alonso



Answer this question

Singleton object garbage collection

  • Eduterio

    1. Keep a reference to the object, and it won't be collected. Perhaps you should just have a static object, and use RemotingServices.Marshal instead - that way you have more control over how and when the object is created. (that's what we do).

    2. Implement ISponsor on the client object, it will renew itself as long as the client is alive. Here is a sample class that you can use:

    [Serializable]
    public class LeaseSponsor : ISponsor
    {
    private TimeSpan LeaseRenewalTime;
    #region ISponsor Members
    public LeaseSponsor(TimeSpan Length)
    {
    LeaseRenewalTime = Length;
    }

    public TimeSpan Renewal(ILease lease)
    {
    return LeaseRenewalTime;
    }
    #endregion
    }


  • Singleton object garbage collection