Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remoting callback object lifetime

I've wrote a piece of code similar to the example in this post: .NET Remoting callback (Pass a callback object to a remote method).

As I found out, if I didn't override MarshalByRefObject.InitializeLifetimeService() After a while, the server failed calling the callback. So I overriden it to return null (infinite lifetime) and it works.

But now I'm a bit worried about garbage collecton:

  1. Will such an object be collected by GC as usual, or remain alive because it was remoted?
  2. I found this method: RemotingServices.Disconnect()

If I call it on my callback object, will it guarantee that the lifetime policy will become irrelevant and it will be garbage collected?

I wanted an expert opinion if I'm doing it right.

Thanks, Gil.

PS. I'm working under the constraints of .NET 2.0, so recommendations to switch to WCF, while correct, are irrelevant. :)

like image 242
Jimbidf Avatar asked Nov 04 '25 12:11

Jimbidf


1 Answers

Ok, it seems that the approach proved itself.

I used an unlimited lease by returning null in MarshalByRefObject.InitializeLifetimeService().
Then, calling RemotingServices.Disconnect() allowed the object to be released properly.

like image 60
Jimbidf Avatar answered Nov 07 '25 08:11

Jimbidf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!