# Does TransportClient need to close?

**URL:** <https://discuss.elastic.co/t/does-transportclient-need-to-close/140124>\
**Category:** Elasticsearch\
**Created:** [July 16, 2018, 9:55am UTC](https://discuss.elastic.co/t/does-transportclient-need-to-close/140124 "2018-07-16T09:55:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xyx](https://avatars.discourse-cdn.com/v4/letter/x/eb8c5e/32.png) [@xyx](https://discuss.elastic.co/u/xyx)\
**Post date:** [July 16, 2018, 9:55am UTC](https://discuss.elastic.co/t/does-transportclient-need-to-close/140124/1 "2018-07-16T09:55:15Z")

</div>

I get a client by the following code,  
Code from : [https://www.elastic.co/guide/en/elasticsearch/client/java-api/6.2/transport-client.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api/6.2/transport-client.html)  
// on startup  
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)  
.addTransportAddress(new TransportAddress(InetAddress.getByName("host1"), 9300))  
.addTransportAddress(new TransportAddress(InetAddress.getByName("host2"), 9300));  
// on shutdown  
client.close();

I put my project on Linux,I always use 'kill pid' to close the project.So the code "client.close()" will not be executed.  
Does this waste a lot of connections of es？

Does TransportClient need to be closed？

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [July 16, 2018, 6:31pm UTC](https://discuss.elastic.co/t/does-transportclient-need-to-close/140124/2 "2018-07-16T18:31:15Z")

</div>

`close()` is needed if you are opening multiple (or recreating) clients. It frees up memory resources used by the client. You are correct that if the entire process is killed, close won't affect anything.

---

<div class="post-metadata">

**Author:** ![xyx](https://avatars.discourse-cdn.com/v4/letter/x/eb8c5e/32.png) [@xyx](https://discuss.elastic.co/u/xyx)\
**Post date:** [July 19, 2018, 1:00am UTC](https://discuss.elastic.co/t/does-transportclient-need-to-close/140124/3 "2018-07-19T01:00:52Z")

</div>

thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 16, 2018, 1:00am UTC](https://discuss.elastic.co/t/does-transportclient-need-to-close/140124/4 "2018-08-16T01:00:56Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
