top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Android - Looper that quits keeps open files/pipes

0 votes
283 views

I noticed that whenever a thread that runs with a Looper object is finished (i.e. Looper.quit() is called), some files remain open (3 files usually). You can see that by running "adb shell ls /proc//fd | wc -l"

This happens because the MessageQueue inside Looper is never freed, although it's never used. Only if I call the finalize() method on the MessageQueue, then these files are freed. The files may remain open hours after the thread is finished.
This causes a problem when these threads run in system process because there are many open files already, and I can't exceed the 1024 file boundary. (BTW even when I call System.gc() it doesn't finalize MessageQueue)

Is there anyway (without using reflection) to have MessageQueue finalize method invoked? It seems to me like a bug in Android that the GC doesn't do it by itself even when the number of open files is big.

posted Jul 25, 2013 by Kevin Peterson

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

GC doesn't clear staled objects if you have some references to them. Good explanations is here: http://dubroy.com/blog/google-io-memory-management-for-android-apps/

answer Jul 26, 2013 by Mandeep Sehgal
0 votes

Speaking very generally, never quit() your looper threads. That method exists mostly for historical and testing reasons. In Real Life™, I recommend that you continue to reuse the same looper thread(s) for the life of the process rather than creating/quitting them.

answer Jul 26, 2013 by Salil Agrawal
Similar Questions
0 votes

I have some query regarding criteria of stable binary of android source code project. Please provide me information about release criteria of android open source project on based success rate of performed testing.

+3 votes

Hi, I want to open another applications like Facebook, google play etc., while user clicks links in the webview of my application. I have given facebook.com link to the buttons. However app doesn't load by clicking that. Please help.

+5 votes

Are there any open sourced live tracking (AR) libraries for Android?

The task I wish to accomplish is to find the floor area of the room in the image captured thru camera. I have tried to use OpenCV and I could not accomplish this without using Markers. Please suggest some other libraries or a working solution with OpenCV.

Thanks in Advance.

+1 vote

In my system application for the latest jeally bean ( 4.3 ), signed with the fitting platform certificate running as android.uid.system. In my manifest, I added the permissions READ_FRAME_BUFFER, ACCESS_SURFACE_FLINGER.

In my app, I'm able to access the SurfaceFlinger service via the ScreenShotClient ( c++ ). Accessing the /dev/graphics/fb0 device directly ( also using native code, c++ ) via open always failed with a permission error.

I wrote an little command line tool, which is able to open the /dev/graphics/fb0. For sure my command line tool is running as root user, and my app is running as system user.

ls -l -a /dev/graphics/fb0 crw-rw---- root graphics 29, 0 2013-09-30 07:31 fb0

For my understanding only the root user, or a member of the graphics group can access the fb0. For my understanding the READ_FRAME_BUFFER permission, is exactly for accessing /dev/graphics/fb? Can someone please give me a hint?

...