File tree 2 files changed +20
-20
lines changed
rcljava/src/main/java/org/ros2/rcljava
2 files changed +20
-20
lines changed Original file line number Diff line number Diff line change @@ -80,31 +80,14 @@ private RCLJava() {}
80
80
81
81
private static void cleanup () {
82
82
for (Node node : nodes ) {
83
- for (Subscription subscription : node .getSubscriptions ()) {
84
- subscription .dispose ();
85
- }
86
-
87
- for (Publisher publisher : node .getPublishers ()) {
88
- publisher .dispose ();
89
- }
90
-
91
- for (Timer timer : node .getTimers ()) {
92
- timer .dispose ();
93
- }
94
-
95
- for (Service service : node .getServices ()) {
96
- service .dispose ();
97
- }
98
-
99
- for (Client client : node .getClients ()) {
100
- client .dispose ();
101
- }
102
-
103
83
node .dispose ();
104
84
}
85
+ nodes .clear ();
86
+
105
87
for (Context context : contexts ) {
106
88
context .dispose ();
107
89
}
90
+ contexts .clear ();
108
91
}
109
92
110
93
static {
Original file line number Diff line number Diff line change 24
24
import org .ros2 .rcljava .consumers .TriConsumer ;
25
25
import org .ros2 .rcljava .contexts .Context ;
26
26
import org .ros2 .rcljava .qos .QoSProfile ;
27
+ import org .ros2 .rcljava .interfaces .Disposable ;
27
28
import org .ros2 .rcljava .interfaces .MessageDefinition ;
28
29
import org .ros2 .rcljava .interfaces .ServiceDefinition ;
29
30
import org .ros2 .rcljava .parameters .ParameterType ;
@@ -343,10 +344,26 @@ public final Collection<Client> getClients() {
343
344
*/
344
345
private static native void nativeDispose (long handle );
345
346
347
+ private <T extends Disposable > void cleanupDisposables (Collection <T > disposables ) {
348
+ for (Disposable disposable : disposables ) {
349
+ disposable .dispose ();
350
+ }
351
+ disposables .clear ();
352
+ }
353
+
354
+ private void cleanup () {
355
+ cleanupDisposables (subscriptions );
356
+ cleanupDisposables (publishers );
357
+ cleanupDisposables (timers );
358
+ cleanupDisposables (services );
359
+ cleanupDisposables (clients );
360
+ }
361
+
346
362
/**
347
363
* {@inheritDoc}
348
364
*/
349
365
public final void dispose () {
366
+ cleanup ();
350
367
nativeDispose (this .handle );
351
368
this .handle = 0 ;
352
369
}
You can’t perform that action at this time.
0 commit comments