Hi Lenny, to be honest I don’t have proofs whether the subscriptions can be garbage-collected efficiently and properly by default without us doing anything.

It’s just precaution and responsible coding as a Java dev IMO. Garbage collection is not simple task and can be expensive. By disposing the the subscription as soon as we are done with that, we make sure that resources like CPU is released timely so that next test can be run immediately. We don’t know when the subscription is garbaged collected otherwise.

Imagine we have 11 tests which has 11 running subscriptions in our XyzTest.java. I’m guessing when all tests are done after N seconds, XzyTest is garbage collected and resources are released and the 11 subscriptions are automatically disposed. Did we really have to keep all 11 subscriptions till the end in that case? With parallelism and timely disposition, we can utilise the resources better and finish the 11 tests in less than N seconds I believe

(I might to be to do some performance tests and share the results in the main article later)

Also, what’s gonna happen if there is an infinite loop inside one of our subscriptions and we never dispose it?

It used to be a pain to release every single variable manually when coding iOS app with Objective C. I’m thinking the amount of efforts required here is very reasonable in contrast, right? :)

Let me know if this answer your question please

Hiring Android engineer shorturl.at/bivJO Clean coder, walker & biker. Hater of inefficiency

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store