File tree 4 files changed +49
-1
lines changed
4 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -334,7 +334,11 @@ - (BOOL)isObjectAlive:(EDOObject *)object {
334
334
335
335
- (BOOL )removeObjectWithAddress : (EDOPointerType)remoteAddress {
336
336
NSNumber *edoKey = [NSNumber numberWithLongLong: remoteAddress];
337
+ __block NSObject *object NS_VALID_UNTIL_END_OF_SCOPE;
337
338
dispatch_sync (_localObjectsSyncQueue, ^{
339
+ // Transfer the ownership of local object to the outer queue, where the object should be
340
+ // released.
341
+ object = self.localObjects [edoKey];
338
342
[self .localObjects removeObjectForKey: edoKey];
339
343
});
340
344
return YES ;
@@ -413,7 +417,14 @@ - (void)startReceivingRequestsForChannel:(id<EDOChannel>)channel {
413
417
// needed for this request. The request handler will process this request
414
418
// properly in its own queue.
415
419
if ([request class ] == [EDOObjectReleaseRequest class ]) {
416
- [EDOObjectReleaseRequest requestHandler ](request, strongSelf);
420
+ dispatch_queue_t executionQueue = strongSelf.executionQueue ;
421
+ if (executionQueue) {
422
+ dispatch_async (executionQueue, ^{
423
+ [EDOObjectReleaseRequest requestHandler ](request, weakSelf);
424
+ });
425
+ } else {
426
+ [EDOObjectReleaseRequest requestHandler ](request, strongSelf);
427
+ }
417
428
} else {
418
429
// Health check for the channel.
419
430
[targetChannel sendData: EDOClientService.pingMessageData withCompletionHandler: nil ];
Original file line number Diff line number Diff line change @@ -388,4 +388,33 @@ - (void)testPassByValueWithLocalObject {
388
388
XCTAssertEqualObjects (localClassName, @" EDOObject" );
389
389
}
390
390
391
+ /* * Tests local object is released on the execution queue if it is released by EDOHostService. */
392
+ - (void )testLocalObjectReleaseOnHostExecutionQueue {
393
+ [self launchApplicationWithPort: EDOTEST_APP_SERVICE_PORT initValue: 5 ];
394
+ EDOHostService *service =
395
+ [EDOHostService serviceWithPort: 2234
396
+ rootObject: [[EDOTestDummyInTest alloc ] initWithValue: 9 ]
397
+ queue: dispatch_get_main_queue ()];
398
+ __block EDOTestDummyInTest *dummy = [[EDOTestDummyInTest alloc ] init ];
399
+ __weak EDOTestDummyInTest *weakDummy = dummy;
400
+ EDOTestDummy *remoteDummy = [EDOClientService rootObjectWithPort: EDOTEST_APP_SERVICE_PORT];
401
+
402
+ XCTestExpectation *expectation = [self expectationWithDescription: @" dummy is released on main." ];
403
+ dummy.deallocHandlerBlock = ^{
404
+ XCTAssertTrue ([NSThread isMainThread ]);
405
+ [expectation fulfill ];
406
+ };
407
+ dummy.block = ^{
408
+ dispatch_sync (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
409
+ dummy = nil ;
410
+ });
411
+ };
412
+
413
+ [remoteDummy returnPlus10AndAsyncExecuteBlock: dummy];
414
+ [self waitForExpectations: @[ expectation ] timeout: 2 .0f ];
415
+ XCTAssertNil (weakDummy);
416
+
417
+ [service invalidate ];
418
+ }
419
+
391
420
@end
Original file line number Diff line number Diff line change 25
25
@property NSNumber *value;
26
26
@property EDOTestDummyInTest *dummyInTest;
27
27
@property void (^block)(void );
28
+ @property (nullable ) void (^deallocHandlerBlock)(void );
28
29
29
30
- (instancetype )initWithValue : (int )value ;
30
31
Original file line number Diff line number Diff line change @@ -39,6 +39,12 @@ - (instancetype)initWithValue:(int)value {
39
39
return self;
40
40
}
41
41
42
+ - (void )dealloc {
43
+ if (_deallocHandlerBlock) {
44
+ _deallocHandlerBlock ();
45
+ }
46
+ }
47
+
42
48
- (int )callTestDummy : (EDOTestDummy *)dummy {
43
49
return self.value .intValue + [dummy returnIdWithInt: 10 ].value + 3 ;
44
50
}
@@ -59,4 +65,5 @@ - (void)invokeBlock {
59
65
self.block ();
60
66
}
61
67
}
68
+
62
69
@end
You can’t perform that action at this time.
0 commit comments