Chinaunix首页 | 论坛 | 博客
  • 博客访问: 463849
  • 博文数量: 145
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1060
  • 用 户 组: 普通用户
  • 注册时间: 2013-08-22 11:52
个人简介

专注计算机技术: Linux Android 云计算 虚拟化 网络

文章分类

全部博文(145)

文章存档

2016年(3)

2015年(21)

2014年(75)

2013年(46)

我的朋友

分类: Android平台

2014-05-03 08:59:20

From 
My Android app seems to not be releasing its views when I move around inside of it with ListView navigation and with the standard Menu key. After a hundred or so different (of the 10 or so unique views) loads, it starts lagging and black screening. 
Error Log:
点击(此处)折叠或打开

  1. 07-01 09:54:42.913: INFO/ActivityManager(1279): Starting: Intent { cmp=com.site.android.conferencecompanion/.Search } from pid 31290
  2. 07-01 09:54:43.013: ERROR/msm7x30.gralloc(1279): /dev/pmem: no more pmem available
  3. 07-01 09:54:43.013: ERROR/msm7x30.gralloc(1279): couldn't open pmem (No such file or directory)
  4. 07-01 09:54:43.013: ERROR/msm7x30.gralloc(1279): gralloc failed err=Out of memory
  5. 07-01 09:54:43.013: WARN/GraphicBufferAllocator(1279): alloc(480, 800, 1, 00000133, ...) failed -12 (Out of memory)
  6. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): Allocated buffers:
  7. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x290740: 1500.00 KiB | 480 ( 480) x 800 | 1 | 0x00000133
  8. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x307448: 60.00 KiB | 102 ( 128) x 120 | 1 | 0x00000133
  9. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x32e4c0: 71.25 KiB | 480 ( 480) x 38 | 1 | 0x00000133
  10. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x3caad8: 60.00 KiB | 102 ( 128) x 120 | 1 | 0x00000133
  11. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x4a47f8: 1346.25 KiB | 480 ( 480) x 718 | 1 | 0x00000133
  12. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x4f9710: 1500.00 KiB | 480 ( 480) x 800 | 1 | 0x00000133
  13. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x54c500: 1500.00 KiB | 480 ( 480) x 800 | 1 | 0x00000133
  14. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x5d1c00: 1500.00 KiB | 480 ( 480) x 800 | 1 | 0x00000133
  15. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x5f5f98: 1500.00 KiB | 480 ( 480) x 800 | 1 | 0x00000133
  16. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x604600: 60.00 KiB | 126 ( 128) x 120 | 1 | 0x00000133
  17. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x60a3d0: 750.00 KiB | 480 ( 480) x 800 | 4 | 0x00000133
  18. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x661270: 1428.75 KiB | 480 ( 480) x 762 | 1 | 0x00000133
  19. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x6830b8: 750.00 KiB | 480 ( 480) x 800 | 4 | 0x00000133
  20. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x70e0e8: 1500.00 KiB | 480 ( 480) x 800 | 1 | 0x00000133
  21. 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x71f238: 71.25 KiB | 480 ( 480)
  22. 07-01 09:54:43.013: ERROR/SurfaceFlinger(1279): Layer::requestBuffer(this=0x189d50), index=0, w=480, h=800 failed (Out of memory)
  23. 07-01 09:54:43.013: ERROR/Surface(31290): Surface (identity=4545) requestBuffer(0, 0, 0, 0, 00000033) returned a buffer with a null handle
  24. 07-01 09:54:43.013: ERROR/Surface(31290): getBufferLocked(0, 0, 0, 0, 00000033) failed (Out of memory)
  25. 07-01 09:54:43.013: ERROR/Surface(31290): dequeueBuffer failed (Out of memory)
  26. 07-01 09:54:43.013: ERROR/ViewRoot(31290): OutOfResourcesException locking surface
  27. 07-01 09:54:43.013: ERROR/ViewRoot(31290): android.view.Surface$OutOfResourcesException
  28. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.view.Surface.lockCanvasNative(Native Method)
  29. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.view.Surface.lockCanvas(Surface.java:314)
  30. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.view.ViewRoot.draw(ViewRoot.java:1457)
  31. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.view.ViewRoot.performTraversals(ViewRoot.java:1259)
  32. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.view.ViewRoot.handleMessage(ViewRoot.java:1860)
  33. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.os.Handler.dispatchMessage(Handler.java:99)
  34. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.os.Looper.loop(Looper.java:123)
  35. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.app.ActivityThread.main(ActivityThread.java:3839)
  36. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at java.lang.reflect.Method.invokeNative(Native Method)
  37. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at java.lang.reflect.Method.invoke(Method.java:507)
  38. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
  39. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
  40. 07-01 09:54:43.013: ERROR/ViewRoot(31290): at dalvik.system.NativeStart.main(Native Method)
  41. 07-01 09:54:43.203: INFO/ActivityManager(1279): Displayed com.site.android.conferencecompanion/.Search: +292ms

adb shell dumpsys window reveals the following:

#1 - #29, junk #30: AppWindowToken{40bbc000 token=HistoryRecord{408cc260 com.site.android.conferencecompanion/.ProgramDates}} ... #142: AppWindowToken{40ba65a8 token=HistoryRecord{40b93808 com.site.android.conferencecompanion/.ProgramSpeakers}}

So, if I understand correctly, something like 112 views are being held in memory. Is there something I can do about this? Is there a check or a flag or a parameter I'm missing? Am I misinterpretting the dump?

Thanks!

asked Jul 1 '11 at 15:05
    
@Scott: I don't think so, how can I be sure? – 
    
Simply use of the static keyword is a good place to start. Here's some rudimentary documentation on leaks in Android: developer.android.com/resources/articles/… – 
    
Can you please clarify what you are doing in code? Is this happening inside one activity? Or are you launching several activities by calling intents when the user selects a ListView item? A code sample of how you launch/load a new view might be good. – 
accepted


A great way to check to see where leaks are coming from is , if you are in Eclipse, Window->Open Perspecive -> DDMS then select the running process from the process selection and use the allocation tracker.Boot the app but DO NOT touch the app before you start the allocation tracker. Then do what you think will cause the problem and then check the allocations every time. This should show you exactly what code is causing a leak.

Also if you post you code we could take a look at it.


@@@:
1

(Even though this was a year ago, I came here via Google)

Something tells me that you have too many views loaded at once and Android can't keep track of them all. * This sounded like not using the ListView correctly, which is something a lot of us are guilty of. Assuming that you have a custom array adapter:

public abstract View getView (int position, View convertView, ViewGroup parent)

When you overload this function, always check convertView.

public abstract View getView (int position, View convertView, ViewGroup parent) {     View view = convertView;     if ( view == null ) {         // create/inflate the view here // 
        ex: view = inflater.inflate(R.layout.bob, null);
         // configure the static parts here     } // 
    configure the dynamic parts here return view; }

Android has a "recycle bin" mechanism for listview views, and will reuse views if all possible. In other words, instead of creating a bunch of different views, it'll grab an old view from the recycle bin.

In your case, you have 10 different kind of views. If they are very similar, you can make a superview and turn on or turn off parts of the view (example being subView.setVisibility(View.GONE)). Just watch out for massive if statement blocks. I haven't used these before, but you should investigate

public abstract int getItemViewType (int position) public abstract int getViewTypeCount ()

This would be better because you don't have to deal with extra fluff, and it should be automatically managed by Android

  • Personally, I'm not 100% sure that this could be it, but I have the feeling that there's a 66% chance it's this


Try extending your Activities so you can see if they are being garbage collected (finalize() being called). Similarly, try extending your Views to help identify if they are being garbage collected.

If you are putting Views and Activities into Collections for caching, trying using collection objects that use WeakReference, such as WeakHashMap. Are you using inner classes in your Views or Activities? If so, these classes holds a reference to the Activity or View and prevent them from being garbage collected. A good example is an AsyncTask that is an inner class. This task runs in its own thread, and can continue to hold on to Views even when you have closed the activity,

Also, look at static variables, are they holding on to objects?

|

This is problem from Surface Flinger, Which will maintain and compose Surfaces of Application into display device.

try this : reduce your layout pixel format in xml file .

|

0

If I may leave a note here:

I had this same logs while I was testing on my Prestigo PMP5080B. My app would also random block.

I have noticed that when I disconnect the USB cable (it is enough to swtich off the connection from the tablet by clicking in settings) the app works OK. I have also noticed that while I am connected to my app using Eclipse and through USB that the SD card can not be mounted but do not know if this problem is connected somehow to my app since I do not store on SD.

hth

|
0

I had the same problem and finally solved it. The solution:

Start your app from Eclipse and play a little with it while constantly observing the LogCat-Console in Eclipse. When starting a new Activity or something like that you should see:

Tag:"WindowManagerImpl", Text:"addView, new view, mViews[1]:....".

The important thing here is the mViews[x]-part. x tells you how many views are active. Now when you start an activity but the mViews-Counter tells you that it has 5-10 new views, then you can be sure that you accidentally create too many views. That way you can find the weak point in your code.

This happened in my game app: everytime I lost the game 5 or more new GameOverActivities were started, because the code, which started a new GameOverActivity was in a loop. So after a few minutes of playing there were 20 unused GameOverViews eating up my resources. (So be careful when starting activities in loops.)

|


阅读(2167) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~