From 5dd32beab3252e052c5b1b45db765b0b81f82cdc Mon Sep 17 00:00:00 2001 From: Tejas Nandanikar Date: Sun, 24 May 2020 14:34:42 +1000 Subject: [PATCH] Add documentation to clarify if ResponseBody.close() is necessary --- retrofit/src/main/java/retrofit2/Response.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/retrofit/src/main/java/retrofit2/Response.java b/retrofit/src/main/java/retrofit2/Response.java index 3a6d570091..d07c965440 100644 --- a/retrofit/src/main/java/retrofit2/Response.java +++ b/retrofit/src/main/java/retrofit2/Response.java @@ -147,12 +147,22 @@ public boolean isSuccessful() { return rawResponse.isSuccessful(); } - /** The deserialized response body of a {@linkplain #isSuccessful() successful} response. */ + /** + * The deserialized response body of a {@linkplain #isSuccessful() successful} response. + * + *

If the body is of type {@link ResponseBody}, {@link ResponseBody#close()} must always be + * called to avoid leaking resources + */ public @Nullable T body() { return body; } - /** The raw response body of an {@linkplain #isSuccessful() unsuccessful} response. */ + /** + * The raw response body of an {@linkplain #isSuccessful() unsuccessful} response. + * + *

Calling {@link ResponseBody#close close} on the response body is unnecessary since it is + * closed internally by Retrofit. + */ public @Nullable ResponseBody errorBody() { return errorBody; }