<> One , Logs with errors
05-26 21:12:53.131 D/serial_port( 1012): Opening serial port /dev/ttyMT2 with
flags0x2 05-26 21:12:53.131 D/serial_port( 1012): open() fd = 1022 05-26 21:12:
53.131 D/serial_port( 1012): Configuring serial port 05-26 21:12:53.131 E/art (
1012): ashmem_create_region failed for 'indirect ref table': Too many open files
05-26 21:12:53.131 W/art ( 1012): Throwing OutOfMemoryError "Could not allocate
JNI Env" 05-26 21:12:53.132 W/DefaultChannelPipeline( 1012): java.lang.
OutOfMemoryError: Could not allocate JNI Env 05-26 21:12:53.132 W/
DefaultChannelPipeline( 1012): at java.lang.Thread.nativeCreate(Native Method)
05-26 21:12:53.132 W/DefaultChannelPipeline( 1012): at java.lang.Thread.start(
Thread.java:730) 05-26 21:12:53.132 W/DefaultChannelPipeline( 1012): at com.
<> Two , When we see this error, the first reaction is whether the memory leak causes the program to fail to apply for memory , However, the fact that I did not …

* Through the simulation software online operation to view Profiler Memory occupied by software , It was found that there was no difference between the two groups 50MB There is no sustained growth on the left and right ; adopt dump
Memory snapshot analysis also found no memory leak , So the problem can be determined that it is not a memory leak .
<> Three , Looking at the error for a long time, I found that there was an important error message on it
05-26 21:12:53.131 E/art ( 1012): ashmem_create_region failed for 'indirect
ref table': Too many open files
* That is to say, there are too many open files in the software , The resulting memory leak , The reason is how to investigate and solve the problem ?
<> Four , That's in Android How many files can be opened in , This can be passed adb shell To view

* By command cat /proc/pid/limits pid That is, the process of the current application ID 1|Droi:/ # cat /proc/1772/limits

* As can be seen from the figure above Max open files by 1024 Files
<> Then how to check which files are opened and not closed in the current application ?

* By command ls /proc/pid/fd | wc -l View the total number of files currently open
* By command ls -l /proc/pid/fd View currently open files

<> Five , Through the simulation of software online operation, it is found that the file of operating serial port has been increasing and has not been closed

* In combination with the actual code , It was found that the serial port was not turned off after using it ; This leads to a continuous increase in each use . // Call at the end of use serialPort.close();
<> Here it is OOM The exception is resolved , Don't be too sad ; The hole I dug was filled with tears

©2019-2020 Toolsou All rights reserved,
( Super detail )Eclipse Using tutorials —— use Eclipse Create first HelloWorld! Database operation 5 code implementation mysql Addition, deletion, modification and query of database What can MCU do , Do you have any interesting works made by MCU or open source hardware Go to the interview after reading this , Steady over ~~ Single linked list of primary data structure (C Language implementation )SQL Comprehensive questions Employee unit comprehensive questions Python Implementation of Hanoi Tower code VHDL——JK trigger It's over , Starting salary 30k