2015-02-10 67 views
2

我正在制作一个android应用程序,可以将视频从服务器传输到android移动设备。我有图像流正常和工作,但15秒后应用程序崩溃。我设法跟踪到抛出OutOfMemoryError。我试图回收位图后,我把它传递给线程来显示它,但我得到的错误“无法重用回收的位图”。我不知道如何解决这个错误,或者即使斜倚它会解决它。我设法跟踪内存错误的行“byte [] data = new byte [size + 1];”但经过研究,我得到了由于位图造成的印象。Android在应用程序中抛出OutOfMemoryError

有其他人有这个问题的问题,并设法解决它?有这方面的帮助将是真棒:d

感谢

LOGCATOUTPUT:

02-10 15:22:15.488 32097-32122/com.google.vrtoolkit.cardboard.samples.treasurehunt I/System.out﹕ 373348 
 
02-10 15:22:16.655 32097-32122/com.google.vrtoolkit.cardboard.samples.treasurehunt I/System.out﹕ 373348 
 
02-10 15:22:17.371 32097-32122/com.google.vrtoolkit.cardboard.samples.treasurehunt I/System.out﹕ 373348 
 
02-10 15:22:18.827 32097-32122/com.google.vrtoolkit.cardboard.samples.treasurehunt I/System.out﹕ 373348 
 
02-10 15:22:29.167 32097-32122/com.google.vrtoolkit.cardboard.samples.treasurehunt I/art﹕ Alloc sticky concurrent mark sweep GC freed 37627(1380KB) AllocSpace objects, 0(0B) LOS objects, 6% free, 114MB/122MB, paused 905us total 7.018ms 
 
02-10 15:22:29.178 32097-32122/com.google.vrtoolkit.cardboard.samples.treasurehunt I/art﹕ Alloc partial concurrent mark sweep GC freed 110(3KB) AllocSpace objects, 2(92MB) LOS objects, 40% free, 22MB/36MB, paused 1.112ms total 11.404ms 
 
02-10 15:22:29.202 32097-32122/com.google.vrtoolkit.cardboard.samples.treasurehunt I/art﹕ Alloc concurrent mark sweep GC freed 141(17KB) AllocSpace objects, 0(0B) LOS objects, 40% free, 22MB/36MB, paused 825us total 23.893ms 
 
02-10 15:22:29.202 32097-32122/com.google.vrtoolkit.cardboard.samples.treasurehunt I/art﹕ Forcing collection of SoftReferences for 1GB allocation 
 
02-10 15:22:29.223 32097-32122/com.google.vrtoolkit.cardboard.samples.treasurehunt I/art﹕ Alloc concurrent mark sweep GC freed 67(2520B) AllocSpace objects, 0(0B) LOS objects, 39% free, 22MB/36MB, paused 2.473ms total 18.440ms 
 
02-10 15:22:29.223 32097-32122/com.google.vrtoolkit.cardboard.samples.treasurehunt E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 1801149826 byte allocation with 15419532 free bytes and 233MB until OOM" 
 
02-10 15:22:29.223 32097-32122/com.google.vrtoolkit.cardboard.samples.treasurehunt E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-1308 
 
    Process: com.google.vrtoolkit.cardboard.samples.treasurehunt, PID: 32097 
 
    java.lang.OutOfMemoryError: Failed to allocate a 1801149826 byte allocation with 15419532 free bytes and 233MB until OOM 
 
      at Socket.ClientThread.run(ClientThread.java:130) 
 
02-10 15:22:29.833 32097-32121/com.google.vrtoolkit.cardboard.samples.treasurehunt I/MainActivity﹕ onRendererShutdown 
 
02-10 15:22:32.793 32097-32122/com.google.vrtoolkit.cardboard.samples.treasurehunt I/Process﹕ Sending signal. PID: 32097 SIG: 9

+0

可能的重复[在将图像加载到位图对象时出现内存不足问题](http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-图像到位图对象) – SMR 2015-02-10 06:20:37

+0

我试着看着,并使用该解决方案,它并没有在我的情况下工作 – user3774031 2015-02-10 06:22:06

回答

5

对Android的5类似的问题,将您的图像/提拉 - nodpi代替/绘制。

编辑:我认为这与使用当前设备DPI自动缩放图像有关。例如,如果仅在/ drawable-mdpi中有大图像,但设备是xxxhdpi,则Android会以mdpi形式提供图像,并尝试将其扩展为匹配xxxhdpi,从而占用太多内存。但是来自/ drawable-nodpi的图像没有缩放,它们就像原样使用。

+0

修复了我的问题+1。 – bhai 2015-10-11 10:14:06

+0

谢谢..它也适用于我..也可以解释我是如何工作的? – 2016-01-05 09:27:45

+0

编辑答案 – Borzh 2016-01-15 16:03:40

相关问题