@@ -162,5 +162,56 @@ def service.fast_method
162162 end
163163 end
164164 end
165+
166+ with "proxy garbage collection" do
167+ it "sends release message when proxy is garbage collected" do
168+ temporary_object = Object . new
169+ server_connection = nil
170+
171+ # Controller that returns an implicitly bound object
172+ controller = Class . new ( Async ::Bus ::Controller ) do
173+ def initialize ( connection , temporary_object )
174+ @connection = connection
175+ @temporary_object = temporary_object
176+ end
177+
178+ def get_temporary_object
179+ # Create an implicit binding and return the proxy:
180+ @connection . proxy ( @temporary_object )
181+ end
182+ end
183+
184+ start_server do |connection |
185+ server_connection = connection
186+ controller_instance = controller . new ( connection , temporary_object )
187+ connection . bind ( :controller , controller_instance )
188+ end
189+
190+ client . connect do |connection |
191+ controller_proxy = connection [ :controller ]
192+
193+ # Get the proxy to the temporary object
194+ temporary_proxy = controller_proxy . get_temporary_object
195+ name = temporary_proxy . __name__
196+
197+ # Verify the object exists on the server and is marked as temporary
198+ expect ( server_connection . objects ) . to have_keys ( name )
199+ expect ( server_connection . objects [ name ] ) . to be ( :temporary? )
200+
201+ temporary_proxy = nil
202+
203+ # Give some time for the finalizer to run:
204+ 10 . times do
205+ GC . start
206+ Fiber . scheduler . yield
207+
208+ # Break as soon as the object is no longer in the server's objects:
209+ break unless server_connection . objects . key? ( name )
210+ end
211+
212+ expect ( server_connection . objects ) . not . to have_keys ( name )
213+ end
214+ end
215+ end
165216end
166217
0 commit comments