In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
The whole process of memory leak testing is as follows:
Start the tested APP in the phone and open DDMS.
Click the button [show heap updates] after selecting [com.example.android.hcgallery] in the DDMS, then switch to the tab [VM Heap], and then click the button [Cause GC].
Constantly manipulate APP and observe Heap. After a period of operation, we found that the Total Size of both% Used and data object is increasing, as shown in the figure. Under normal circumstances, Total Size will be stable within a certain range.
Figure VM Heap 1
It will continue to increase even after Cause GC, as shown in the figure
Figure VM Heap 2
At this time, we suspect that if there may be a memory leak in the long run, in order to further analyze, we click the button [Dump HPROF File] to get a file with the suffix hprof (it takes a long time to generate the file, please wait patiently).
Use the command hprof-conv to convert the resulting hprof file to standard hprof so that MAT can recognize it.
Use MAT to open the converted hprof file, and select [Leak Suspects Report] in the figure. Then you will see a summary information, as shown in the figure. It just gives you a macro concept and tells you the proportion of certain problems, which is not substantially helpful to the analysis.
Clicking the column icon button [Histogram] generates a view that displays a list of class instances, where Shallow Heap represents the amount of memory consumed by the object itself, excluding the objects it references. Retained Heap represents the sum of the size of the current object and the size of the object to which the current object can be referenced directly or indirectly.
Sorting from large to small in the Shallow Heap column, we find that byte [] accounts for the largest proportion. After selecting it, right-click and select [List objects] > [with incoming referenes] to drill, as shown in the figure.
Figure Histogram view
Once again, sort by the Shallow Heap column from largest to smallest, select a larger object and expand its path in turn, as shown in the figure. Here we focus on our own code, that is, com.example.android.hcgallery.ContentFragment, and we find that mBitmap is suspicious. This method is suitable for friends who are familiar with the code.
Figure with incoming references
In addition to the above methods, you can also analyze by excluding weak references, which can reduce interference factors. First, sort Retained Heap from largest to smallest, then right-click the largest, select [Path To GC Roots] > [exclude weak references] to get the data as shown in the figure. It is found that sBitmapCache accounts for a large proportion of this variable, which may be problematic.
Figure exclude weak references
In Xiaoqiang class, there are strong references, weak references and soft references in Java. Here is a popularization for you:
Strong reference: garbage collection will not reclaim it, we need to actively set it to null.
Weak reference: as the name implies, when garbage collection finds that it has only weakly referenced objects, it will be reclaimed regardless of the current memory space.
Soft reference: if it only has a soft reference object and there is enough memory space, the garbage collector will not collect it. But if there is not enough memory space, it will be recycled.
After checking the code, it is found that sBitmapCache is that there is no recycle drop after the use of static HashMap,mBitmap.
Finally, modify the code to mBitmap.recycle () when mBitmap! = null.
At least you won't feel confused when you do it step by step, but there are rules to follow. In addition, the analysis of some memory leaks may not be analyzed at once and need to be analyzed many times, which tests everyone's patience. In fact, as long as you remember that there are rules to follow in analysis, patience is essential, and any problem can be solved.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Http://www.powerxing.com/install-hadoop/
© 2024 shulou.com SLNews company. All rights reserved.