private void shutDown() { try { try { Thread.sleep(2000); } catch (InterruptedException e) { } System.out.println("nulling reference"); sipStack.deleteListeningPoint(tcpListeningPoint); sipStack.deleteListeningPoint(udpListeningPoint); // This will close down the stack and exit all threads tcpProvider.removeSipListener(this); udpProvider.removeSipListener(this); while (true) { try { sipStack.deleteSipProvider(udpProvider); sipStack.deleteSipProvider(tcpProvider); break; } catch (ObjectInUseException ex) { try { Thread.sleep(2000); } catch (InterruptedException e) { continue; } } } sipStack = null; tcpProvider = null; udpProvider = null; this.contactHeader = null; addressFactory = null; headerFactory = null; messageFactory = null; this.udpListeningPoint = null; this.tcpListeningPoint = null; this.reInviteCount = 0; System.gc(); // Redo this from the start. if (counter < 10) this.init(); else counter++; } catch (Exception ex) { ex.printStackTrace(); } }