Android - view.Surface OutOfResourcesException

My Android app doesn't seem to release my views when I navigate inside it using the ListView navigation and with a standard menu key. After hundreds or so different (out of 10 or so unique species) are loaded, it begins to linger in black shielding.

Error Log:

07-01 09:54:42.913: INFO/ActivityManager(1279): Starting: Intent { cmp=com.site.android.conferencecompanion/.Search } from pid 31290 07-01 09:54:43.013: ERROR/msm7x30.gralloc(1279): /dev/pmem: no more pmem available 07-01 09:54:43.013: ERROR/msm7x30.gralloc(1279): couldn't open pmem (No such file or directory) 07-01 09:54:43.013: ERROR/msm7x30.gralloc(1279): gralloc failed err=Out of memory 07-01 09:54:43.013: WARN/GraphicBufferAllocator(1279): alloc(480, 800, 1, 00000133, ...) failed -12 (Out of memory) 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): Allocated buffers: 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x290740: 1500.00 KiB | 480 ( 480) x 800 | 1 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x307448: 60.00 KiB | 102 ( 128) x 120 | 1 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x32e4c0: 71.25 KiB | 480 ( 480) x 38 | 1 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x3caad8: 60.00 KiB | 102 ( 128) x 120 | 1 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x4a47f8: 1346.25 KiB | 480 ( 480) x 718 | 1 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x4f9710: 1500.00 KiB | 480 ( 480) x 800 | 1 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x54c500: 1500.00 KiB | 480 ( 480) x 800 | 1 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x5d1c00: 1500.00 KiB | 480 ( 480) x 800 | 1 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x5f5f98: 1500.00 KiB | 480 ( 480) x 800 | 1 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x604600: 60.00 KiB | 126 ( 128) x 120 | 1 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x60a3d0: 750.00 KiB | 480 ( 480) x 800 | 4 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x661270: 1428.75 KiB | 480 ( 480) x 762 | 1 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x6830b8: 750.00 KiB | 480 ( 480) x 800 | 4 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x70e0e8: 1500.00 KiB | 480 ( 480) x 800 | 1 | 0x00000133 07-01 09:54:43.013: DEBUG/GraphicBufferAllocator(1279): 0x71f238: 71.25 KiB | 480 ( 480) 07-01 09:54:43.013: ERROR/SurfaceFlinger(1279): Layer::requestBuffer(this=0x189d50), index=0, w=480, h=800 failed (Out of memory) 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 07-01 09:54:43.013: ERROR/Surface(31290): getBufferLocked(0, 0, 0, 0, 00000033) failed (Out of memory) 07-01 09:54:43.013: ERROR/Surface(31290): dequeueBuffer failed (Out of memory) 07-01 09:54:43.013: ERROR/ViewRoot(31290): OutOfResourcesException locking surface 07-01 09:54:43.013: ERROR/ViewRoot(31290): android.view.Surface$OutOfResourcesException 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.view.Surface.lockCanvasNative(Native Method) 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.view.Surface.lockCanvas(Surface.java:314) 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.view.ViewRoot.draw(ViewRoot.java:1457) 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.view.ViewRoot.performTraversals(ViewRoot.java:1259) 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.view.ViewRoot.handleMessage(ViewRoot.java:1860) 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.os.Handler.dispatchMessage(Handler.java:99) 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.os.Looper.loop(Looper.java:123) 07-01 09:54:43.013: ERROR/ViewRoot(31290): at android.app.ActivityThread.main(ActivityThread.java:3839) 07-01 09:54:43.013: ERROR/ViewRoot(31290): at java.lang.reflect.Method.invokeNative(Native Method) 07-01 09:54:43.013: ERROR/ViewRoot(31290): at java.lang.reflect.Method.invoke(Method.java:507) 07-01 09:54:43.013: ERROR/ViewRoot(31290): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 07-01 09:54:43.013: ERROR/ViewRoot(31290): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 07-01 09:54:43.013: ERROR/ViewRoot(31290): at dalvik.system.NativeStart.main(Native Method) 07-01 09:54:43.203: INFO/ActivityManager(1279): Displayed com.site.android.conferencecompanion/.Search: +292ms 

adb shell dumpsys window shows 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 in memory. Is there anything I can do about it? Is there a check or flag or parameter that I am missing? Am I misinterpreting a dump?

Thanks!

+4
source share
7 answers

A great way to check where the leak occurs is if you are in Eclipse, Window-> Open Perspecive → DDMS, then select the running process from the process selection and use the allocation manager. Download the application, but DO NOT touch the application before starting the distribution tracker. Then do what you think will cause the problem, and then check the distributions every time. This should show you which code is causing the leak.

Also, if you publish a code, we can take a look at it.

+3
source

(Despite the fact that a year ago I came here through Google)

Something tells me that you have too many views downloaded immediately, and Android cannot track them all. * It sounded like it wasn’t right to use ListView, that many of us are guilty. Assuming you have an adapter 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” mechanism for list views, and it will reuse views, if possible. In other words, instead of creating several different views, it will capture the old view from the basket.

In your case, you have 10 different types. If they are very similar, you can supervise and enable or disable parts of the view (for example, subView.setVisibility (View.GONE)). Just watch out for massive if blocks. I have not used them before, but you should research

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

That would be better, because you do not need to deal with extra fluff, and it should be automatically controlled by Android

  • Personally, I am not 100% sure that this may be so, but I have the feeling that he has a 66% chance of this.
+1
source

Try expanding your actions so that you can see if they are garbage collected (finalize () is called). Likewise, try to expand your ideas to help determine if they are garbage collected.

If you add views and actions to collections for caching, try using collection objects that use WeakReference, such as WeakHashMap. Do you use inner classes in your views or actions? If so, these classes contain a reference to an Activity or View and do not allow them to collect garbage. A good example is AsyncTask, which is an inner class. This task runs in its own thread and can continue to hold impressions even when you close activity,

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

0
source

This is a problem with the Surface Flinger, which will support and compose the application surfaces in the display device.

try the following: reduce the layout format in xml format.

0
source

If I can leave a note here:

I had the same magazines while I tested my Prestigo PMP5080B. My application will also be a random block.

I noticed that when I disconnect the USB cable (just disconnect the connection from the tablet by clicking in the settings), the application works fine. I also noticed that although I am connected to my application using Eclipse and via USB, the SD card cannot be mounted, but I do not know if this problem is related to my application, since I did not store it on SD.

Hth

0
source

I had the same problem and finally it was resolved. Decision:

Launch the application from Eclipse and play with it a little while constantly watching the LogCat console in Eclipse. When you start a new action or something similar, you should see:

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

mViews[x]-part is important mViews[x]-part . x shows the number of views. Now, when you start the action, but mViews-Counter tells you that it has 5-10 new views, you can be sure that you accidentally created too many views. This way you can find a weak point in your code.

This happened in my game application: every time I lost the game, 5 or more new GameOverActivities were launched, because the code that started the new GameOverActivity was in a loop. Thus, after a few minutes of the game, there were 20 unused GameOverViews that absorb my resources. (Therefore, be careful when starting actions in loops.)

0
source

In my case, the error occurred because I used the Window class to change the color of the status bar, which is only supported in build versions for Android, newer 21. Add the following code to the code, and it may work

 if(Build.VERSION.SDK_INT >= 21) { //... your code with Window class here } 
0
source

All Articles