diff options
author | Joe Shaw <joeshaw@novell.com> | 2005-03-09 04:36:15 +0000 |
---|---|---|
committer | Joe Shaw <joeshaw@novell.com> | 2005-03-09 04:36:15 +0000 |
commit | 2958e723fc996e2dd7edfdc6ac53dcdf48323549 (patch) | |
tree | c031fe0f0f40e868f18eb3e257667856c1d9f4fc /mono/ProxyBuilder.cs | |
parent | d96c9e465abb291cb943a1b4ec3643de4b3f6423 (diff) |
2005-03-08 Joe Shaw <joeshaw@novell.com>
Fix a bunch of lifecycle and memory management problems
in the mono bindings.
* mono/Arguments.cs (Arguments): Implement IDisposable
* mono/Bus.cs (Bus): Don't allow public instantiation. This is
strictly a static class.
* mono/Connection.cs: Move the DBusObjectPathVTable and associated
delegates into this file.
(Connection): Implement IDisposable.
(Dispose): Disconnect the connection and set the raw connection
pointer to IntPtr.Zero.
(~Connection): Call Dispose().
(RegisterObjectPath): Added. Manages the registration of object
paths so we can cleanly disconnect them at dispose/finalize time.
(UnregisterObjectPath): Ditto.
(set_RawConnection): Unregister all of the object paths when
changing the underlying DBusConnection. Add them back onto the
new connection, if any.
* mono/Handler.cs: Don't implement IDisposable; it doesn't use any
more unmanaged resources anymore, so it's not necessary. Move all
the DBusObjectPathVTable stuff out of here.
(Handler): Save references to our delegates so that they don't get
finalized. Call Connection.RegisterObjectPath() instead of
dbus_connection_register_object_path() directly.
(Message_Called): Dispose the message after we're finished with
it.
* mono/Message.cs (Message): Implement IDisposable.
(Dispose): Dispose the Arguments, and set the RawMessage to
IntPtr.Zero.
(SendWithReplyAndBlock): We own the ref to the reply that comes
back from dbus_connection_send_with_reply_and_block() so add a
comment about that and unref it after we've constructed a managed
MethodReturn class around it. Fixes a big, big leak.
* mono/ProxyBuilder.cs: Reflect into Message to get the Dispose
method.
(BuildSignalHandler): After we've sent the Signal message, dispose
of it.
(BuildMethod): Dispose of the method call and reply messages after
we've sent the message and extracted the data we want from the
reply.
* mono/Service.cs (UnregisterObject): Don't call handler.Dispose()
anymore.
(Service_FilterCalled): Dispose of the message after we're
finished with it.
Diffstat (limited to 'mono/ProxyBuilder.cs')
-rw-r--r-- | mono/ProxyBuilder.cs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/mono/ProxyBuilder.cs b/mono/ProxyBuilder.cs index 80449093..fefac473 100644 --- a/mono/ProxyBuilder.cs +++ b/mono/ProxyBuilder.cs @@ -35,6 +35,8 @@ namespace DBus new Type[0]); private static MethodInfo Message_SendMI = typeof(Message).GetMethod("Send", new Type[0]); + private static MethodInfo Message_DisposeMI = typeof(Message).GetMethod("Dispose", + new Type[0]); private static MethodInfo Arguments_GetEnumeratorMI = typeof(Arguments).GetMethod("GetEnumerator", new Type[0]); private static MethodInfo IEnumerator_MoveNextMI = typeof(System.Collections.IEnumerator).GetMethod("MoveNext", @@ -197,7 +199,6 @@ namespace DBus // Generate the locals LocalBuilder methodCallL = generator.DeclareLocal(typeof(MethodCall)); methodCallL.SetLocalSymInfo("signal"); - LocalBuilder replyL = generator.DeclareLocal(typeof(MethodReturn)); //generator.EmitWriteLine("Signal signal = new Signal(...)"); generator.Emit(OpCodes.Ldsfld, serviceF); @@ -224,6 +225,10 @@ namespace DBus generator.Emit(OpCodes.Ldloc_0); generator.EmitCall(OpCodes.Callvirt, Message_SendMI, null); + //generator.EmitWriteLine("signal.Dispose()"); + generator.Emit(OpCodes.Ldloc_0); + generator.EmitCall(OpCodes.Callvirt, Message_DisposeMI, null); + //generator.EmitWriteLine("return"); generator.Emit(OpCodes.Ret); } @@ -310,6 +315,15 @@ namespace DBus } } + // Clean up after ourselves + //generator.EmitWriteLine("methodCall.Dispose()"); + generator.Emit(OpCodes.Ldloc_0); + generator.EmitCall(OpCodes.Callvirt, Message_DisposeMI, null); + + //generator.EmitWriteLine("reply.Dispose()"); + generator.Emit(OpCodes.Ldloc_1); + generator.EmitCall(OpCodes.Callvirt, Message_DisposeMI, null); + if (method.ReturnType != typeof(void)) { generator.Emit(OpCodes.Ldloc_3); } |