new DemoSoap().request();
A DemoSoap object is DemoSoap and its request() method is called, and the object is entitled to GC. The only purpose of creating an instance of this object was to call request() once, so there is no need to store a link to this object in the future. In your particular case, I do not think it matters a lot.
But an unnecessary reference to an object that you do not need in the future can be bad. Let's pretend that
void somemethod() { Demo demo = new Demo(); demo.request(); // purpose of demo ends here . ....... ........ lots of processing in between ....... // demo still refers to an object in heap uselessly . }
PS: I learned that itβs good practice to release links as quickly as reasonably possible to release.
source share