nhachicha / SnappyDB

A key-value database for Android
1.78k stars 220 forks source link

序列化导致oom #104

Open dreamofxw opened 6 years ago

dreamofxw commented 6 years ago

java.lang.OutOfMemoryError: Failed to allocate a 751242068 byte allocation with 8388576 free bytes and 242MB until OOM at com.esotericsoftware.kryo.io.Input.readString(Input.java:464) at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:132) at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:115) at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:641) at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:99) at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:528) at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:657) at com.snappydb.internal.DBImpl.getObject(DBImpl.java:276) at com...utils.NOsqlUtil.get_userInfoBean(NOsqlUtil.java:87) at com...activity.SplashFragment.onCreateView(SplashFragment.java:144) at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5418) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1037) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832) 以上是oom 日志 下面附get_userInfoBean方法

public static UserInfoBean get_userInfoBean() { DB snappydb; UserInfoBean myObject = null; try { snappydb = DBFactory.open(Utilities.getApplicationContext()); if (snappydb.exists("userInfoBean" + SPUtils.get**Id(Utilities.getApplicationContext()))) { myObject = snappydb.getObject("userInfoBean" + SPUtils.getUserId(Utilities.getApplicationContext()), UserInfoBean.class); // myObject = snappydb.getObjectArray("userInfoBean" + GlobalParams.uid, UserInfoBean.class); } } catch (SnappydbException e) { e.printStackTrace();

    }finally{
     }
    return myObject == null ? new UserInfoBean() : myObject;
}
kevin-zhan commented 6 years ago

userInfoBean is too heavy. And it has nothing to do with the repo, I think you'd better redesign the class.