Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a server that publishes it's URIs using .NET Remoting to enable clients to connect and use its services. The client looks like Windows Explorer with a tree view and a list view that contain network objects. the user can navigate the network and look at the objects on it. All objects obtained from the server using MarshalByRefObject are created in the server and references to them returned to the client. when the view changes the objects loose their references and are garbage collected. During normal operation this works correctly. However if a network event occurs (an object's status changes) the service generates an asynchronous event using the .Net Remoting framework, that is sent to all the attached clients. it contains parameters that detail the action to be taken and the object's path. When the object is updated in the client, a new object is obtained from the server and that object is displayed. This leaks memory. I have inspected the managed heap using the sos.dll and VS's intermediate window and the objects have strong references to them from the .Net Remoting. Disconnecting all of the clients does not release the memory. I don't understand why this is happening and would like some help/suggestions as to the cause please.
Posted

If I am understanding your problem correctly it sounds like you have an even that isn't freed. The way I found to solve this (when using custom objects) was to implement IDisposable and force the events to be cleared.
 
Share this answer
 
I Fixed this problem in the end by altering the design.

Garbage collection by counting and pinging references only works reliably if the objects remain within the same AppDomain (program to you and me). Therefore in a client/server application you need to do something more:

1. change the .config of the server and clients to expose a tcp channel 0
of typeFilterLevel="Full"

2. Expose the ILease interface by override GetLifetimeService() and make it pass back an object that the client casts to ILease.

3. code the client to instantiate a class that implements ISponsor.

4. This is used to register the sponsor with the ILease interface of the marshalByReference object.

5. unregister your objects when you don't need them anymore.

This effectively passes the burden of responsibility onto the client for GCollection. It could have been also done by making copies of the objects in the clients OR pass by value instead of MBR, both of which would have taken too much refactoring.

JB
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900