Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

本地txt打开会出现OutOfMemoryError #26

Closed
eric0815 opened this issue Jan 6, 2018 · 1 comment
Closed

本地txt打开会出现OutOfMemoryError #26

eric0815 opened this issue Jan 6, 2018 · 1 comment

Comments

@eric0815
Copy link

eric0815 commented Jan 6, 2018

操作步骤,清理后台,打开IReader,载入一个本地txt文件,从书架打开,返回书架,再点击任意一个txt都会黑屏
后台报错信息:

01-06 22:47:20.552 2040-2059/com.example.newbiechen.ireader I/art: WaitForGcToComplete blocked for 5.419s for cause Background
01-06 22:47:20.552 2040-2040/com.example.newbiechen.ireader I/art: Waiting for a blocking GC Alloc
01-06 22:47:20.552 2040-2132/com.example.newbiechen.ireader I/art: Waiting for a blocking GC Alloc
01-06 22:47:20.577 2040-2040/com.example.newbiechen.ireader I/art: WaitForGcToComplete blocked for 875.902ms for cause Alloc
01-06 22:47:20.577 2040-2040/com.example.newbiechen.ireader I/art: Starting a blocking GC Alloc
01-06 22:47:20.578 2040-2132/com.example.newbiechen.ireader I/art: WaitForGcToComplete blocked for 328.382ms for cause Alloc
01-06 22:47:20.578 2040-2132/com.example.newbiechen.ireader I/art: Starting a blocking GC Alloc
01-06 22:47:20.578 2040-2040/com.example.newbiechen.ireader W/System.err: java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.
01-06 22:47:20.578 2040-2040/com.example.newbiechen.ireader W/System.err: at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:111)
01-06 22:47:20.578 2040-2040/com.example.newbiechen.ireader W/System.err: at android.os.Handler.handleCallback(Handler.java:751)
01-06 22:47:20.578 2040-2040/com.example.newbiechen.ireader W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
01-06 22:47:20.578 2040-2040/com.example.newbiechen.ireader W/System.err: at android.os.Looper.loop(Looper.java:159)
01-06 22:47:20.578 2040-2040/com.example.newbiechen.ireader W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6363)
01-06 22:47:20.578 2040-2040/com.example.newbiechen.ireader W/System.err: at java.lang.reflect.Method.invoke(Native Method)
01-06 22:47:20.578 2040-2040/com.example.newbiechen.ireader W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1096)
01-06 22:47:20.578 2040-2040/com.example.newbiechen.ireader W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:883)
01-06 22:47:20.578 2040-2040/com.example.newbiechen.ireader W/System.err: Caused by: java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack trace available
01-06 22:47:20.578 2040-2040/com.example.newbiechen.ireader E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.newbiechen.ireader, PID: 2040
java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.
at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:111)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:159)
at android.app.ActivityThread.main(ActivityThread.java:6363)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1096)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:883)
Caused by: java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack trace available
01-06 22:47:20.590 2040-2040/com.example.newbiechen.ireader I/Process: killProcess pid=2040
java.lang.RuntimeException
at android.os.Process.killProcess(Process.java:1258)
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:111)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
at io.reactivex.plugins.RxJavaPlugins.uncaught(RxJavaPlugins.java:288)
at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:282)
at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:113)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:159)
at android.app.ActivityThread.main(ActivityThread.java:6363)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1096)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:883)
01-06 22:47:20.590 2040-2040/com.example.newbiechen.ireader I/Process: Sending signal. PID: 2040 SIG: 9

@newbiechen1024
Copy link
Owner

阅读界面 OOM 崩溃的原因是这样的:

  1. 我是通过使用 PageView@onSizeChanged() 来获取当前屏幕的大小的。
  2. 在解析文本,加载章节的代码中,具体在 PageLoader@loadPages() 中,会根据 mVisibleHeght 即当前屏幕的高度,进行加载章节。
  3. 某些情况下 loadPages() 会在 onSizeChanged() 完成之前执行,导致获取到的 height 一直为 0 ,导致 loadPagess() 中 while 循环一直进行不会退出。

结论就是 onSizeChanged() 是异步执行,转换成同步回调的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants