samedi 25 avril 2015

Image adapter leaking memory?


I have a simple ListActivity that shows images and I inizialize my OkHttpClient for Picasso Builder in the constructor of the image adapter:

picassoClient = new OkHttpClient();
picassoClient.interceptors().add(new Interceptor() {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request newRequest = chain
            .request()
            .newBuilder()
            .addHeader("Cookie","xyz")
            .build();

        return chain.proceed(newRequest);
    }
});

new Picasso.Builder(context).downloader(new OkHttpDownloader(picassoClient)).build();

then in getView() I use Picasso to load images in ImageView:

Picasso.with(context).load(xyzUrl).fit().centerCrop().into(vImage);

It works well, but on device's rotation i see that heap size sometimes slowly grows and sometimes remains stable. Am i leaking memory or is there something wrong in code?

EDIT: I inserted this code after Picasso's call in the getView()

if (BuildConfig.DEBUG) {
    Log.i("HEAP SIZE",
    String.valueOf(Runtime.getRuntime().totalMemory() / 1024));
}

and I found that the heap size's growth happens in the getView() after loading bitmap into ImageView. What is wrong?


Aucun commentaire:

Enregistrer un commentaire