Sticky concurrent mark cleanup GC released
•
Android
I'm trying to issue a simple rest request through retrofit and encounter many GC errors. I really don't know how to solve it. I try to put more memory on the simulator, but the problem still exists. When making a synchronous call, response < list < user > response = userscall. Execute(); The following exceptions
java.lang.RuntimeException: An error occurred while executing doInBackground()
android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Cause by: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 2 path $
at com.google.gson.stream.JsonReader.nextString(JsonReader.java:831)
at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:422)
at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:410)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25)
at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:116)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:89)
And use the POJO model response < list < user > response = userscall. Execute(); then
04-09 07:37:23.897 13396-13411/? I/art: Clamp target GC heap from 111MB to 96MB
04-09 07:37:23.897 13396-13411/? I/art: Background partial concurrent mark sweep GC freed 3104(48KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 7.520ms total 194.127ms
04-09 07:37:23.897 13396-13396/? I/art: WaitForGcToComplete blocked for 182.909ms for cause Alloc
04-09 07:37:23.929 13396-13411/? I/art: Background sticky concurrent mark sweep GC freed 128(5KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 8.237ms total 31.761ms
04-09 07:37:23.929 13396-13396/? I/art: WaitForGcToComplete blocked for 18.171ms for cause Alloc
04-09 07:37:24.130 13396-13411/? I/art: Clamp target GC heap from 111MB to 96MB
04-09 07:37:24.130 13396-13411/? I/art: Background partial concurrent mark sweep GC freed 5784(90KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 9.388ms total 200.412ms
04-09 07:37:24.130 13396-13396/? I/art: WaitForGcToComplete blocked for 200.758ms for cause Alloc
04-09 07:37:24.158 13396-13411/? I/art: Background sticky concurrent mark sweep GC freed 1710(34KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 6.897ms total 27.286ms
04-09 07:37:24.158 13396-13396/? I/art: WaitForGcToComplete blocked for 18.297ms for cause Alloc
04-09 07:37:24.346 13396-13396/? I/art: Clamp target GC heap from 111MB to 96MB
04-09 07:37:24.346 13396-13396/? I/art: Alloc partial concurrent mark sweep GC freed 2092(33KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 5.943ms total 188.191ms
04-09 07:37:24.370 13396-13396/? I/art: Alloc sticky concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 8.501ms total 23.440ms
04-09 07:37:24.566 13396-13396/? I/art: Clamp target GC heap from 111MB to 96MB
04-09 07:37:24.566 13396-13396/? I/art: Alloc concurrent mark sweep GC freed 9(12KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 6.105ms total 195.296ms
04-09 07:37:24.566 13396-13411/? I/art: WaitForGcToComplete blocked for 395.241ms for cause Background
04-09 07:37:24.598 13396-13411/? I/art: Background sticky concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 6.138ms total 29.195ms
04-09 07:37:24.598 13396-13396/? I/art: WaitForGcToComplete blocked for 29.063ms for cause Alloc
04-09 07:37:24.775 13396-13396/? I/art: Clamp target GC heap from 111MB to 96MB
04-09 07:37:24.775 13396-13396/? I/art: Alloc partial concurrent mark sweep GC freed 16(56KB) AllocSpace objects, 1(54KB) LOS objects, 0% free, 95MB/96MB, paused 6.803ms total 177.429ms
My code:
Gson gson =
new GsonBuilder()
.registerTypeAdapter(Usuario.class, new UsuarioDeserializer())
.registerTypeAdapter(Date.class, new CustomDateDeserializer())
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(ConstantesUtil.URL_BASE)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
UsuariosAPI usuarioApi = retrofit.create(UsuariosAPI.class);
Usuario usuario = new Usuario(login, senha);
Call<List<Usuario>> usuarios = usuarioApi.getUsuarios(usuario);
usuarios.enqueue(new Callback<List<Usuario>>() {
@Override
public void onResponse(Call<List<Usuario>> call, Response<List<Usuario>> response) {
List<Usuario> usuarios = response.body();
for (Usuario u: usuarios) {
Log.i(TAG, u.getNome());
}
}
@Override
public void onFailure(Call<List<Usuario>> call, Throwable t) {
}
});
resolvent:
I realized that this problem occurs when the model (in your case, "usuario") has member variables that cause serialization problems (infinite GC loops)
public class Usuario {
@SerializedName("id")
public String id;
// the following will cause infinite loop of GC
public TextView problemView;
// use transient keyword will solve the problem in GC infinite loop
private transient TextView okView;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码