<> 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.
azhon.device.MoneyMachine.init(MoneyMachine.java:79)
<> 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

Technology
©2019-2020 Toolsou All rights reserved,
One is called “ Asking for the train ” A small village Finally got the train Spring Boot Lesson 16 :SpringBoot Implementation of multithreading with injection class Chrome OS, For programmers and Windows What does it mean ? Internet Marketing JAVA Convert a string to a numeric type I've been drinking soft water for three years ? What is the use of soft water and water softener You don't know ——HarmonyOS Talking about uni-app Page value transfer problem JavaScript Medium Call and ApplySparkSQL Achieve partition overlay write Character recognition technology of vehicle license plate based on Neural Network