简体   繁体   中英

Why did my app run out of memory?

Can anyone make sense of this? It just performed two garbage collections and has 16MB free. So why did it fail to allocate 8MB?

09-06 19:08:36.335: V/MediaPlayerService(5439): [102] isPlaying: 0
09-06 19:08:36.421: D/dalvikvm(17483): GC_FOR_MALLOC freed 13K, 39% free 16709K/27079K, external 2357K/2773K, paused 139ms
09-06 19:08:36.421: I/dalvikvm-heap(17483): Forcing collection of SoftReferences for 8520570-byte allocation
09-06 19:08:36.522: D/dalvikvm(17483): GC_FOR_MALLOC freed <1K, 39% free 16708K/27079K, external 2357K/2773K, paused 95ms
09-06 19:08:36.522: E/dalvikvm-heap(17483): Out of memory on a 8520570-byte allocation.
09-06 19:08:36.522: I/dalvikvm(17483): "Thread-19" prio=5 tid=12 RUNNABLE
09-06 19:08:36.522: I/dalvikvm(17483):   | group="main" sCount=0 dsCount=0 obj=0x411da000 self=0x3863e8
09-06 19:08:36.522: I/dalvikvm(17483):   | sysTid=17496 nice=0 sched=0/0 cgrp=default handle=3695904
09-06 19:08:36.522: I/dalvikvm(17483):   | schedstat=( 8278991686 2222930914 7642 )
09-06 19:08:36.522: I/dalvikvm(17483):   at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:~91)
09-06 19:08:36.522: I/dalvikvm(17483):   at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:216)
09-06 19:08:36.522: I/dalvikvm(17483):   at org.jsoup.helper.DataUtil.readToByteBuffer(DataUtil.java:114)
09-06 19:08:36.522: I/dalvikvm(17483):   at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:437)
09-06 19:08:36.522: I/dalvikvm(17483):   at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:391)
09-06 19:08:36.522: I/dalvikvm(17483):   at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:157)
09-06 19:08:36.522: I/dalvikvm(17483):   at org.jsoup.helper.HttpConnection.get(HttpConnection.java:146)

I think the second log line may be confusing you. The wording is a little misleading, but I'm pretty sure it's saying there's only about 10 megs free: 16709K / 27079K is about 61.7%, so 16709K is presumably the amount of memory used , not free.

But 10 megs is still greater than the 8 megs being requested. The problem is probably that your app has been running long enough to have noticeable memory fragmentation. That is, there very well may be 10 megs free total, but it's all (or at least sufficiently) scattered among other bits of actively used memory, such that there isn't a contiguous swath of it to give to your app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM