users@jersey.java.net

Proper way to structure code so that Client instances can be cleaned up

From: Gavin Bong <malaisien_at_gmail.com>
Date: Wed, 16 Sep 2009 15:05:19 +0800

Hi,

Currently I am creating a WebResource inside a method like this:


    private WebResource resource( String user )
    {
        ClientConfig config = new DefaultClientConfig();
        Client client = Client.create(config);
        client.addFilter( new LoggingFilter() );
        WebResource resource = client.resource( _endpoint + "/" + user );
        return resource;
    }


As you can see, I am not calling client.destroy(). Am I correct to say
that I am probably leaking memory because of this ?

If multiple threads call my method, multiple instances of Client &
WebResource will be created.
When should I call Client.destroy() ? During servlet context shutdown ?

-- 
Sincères salutations,
Gavin Bong
Rien ne sert d'être vivant, s'il faut qu'on travaille - André Breton
If you do things well, do them better. Be daring, be first be
different, be just. - Anita Roddick