Types of memory leaks in a garbage-collected language running in virtual machines (ie, Dalvik)

前提是你 提交于 2019-12-11 12:02:38

问题


Aren't there two types of memory leaks when dealing with a garbage collected language: user-coded and runtime-environment? That is, poor user code (say lots of global static references) vs bugs in the runtime, or are they considered one in the same? Are the tools used to find them the same typically?


回答1:


As I know, poor user code is the main problem for leading memory leak. And In Dalvik, the java-heap uses dlmalloc for allocing memory, this may lead more Memory fragmentation; even if you call GC, the VM may not trim the java-heap because of 4K per page in Linux being the basic unit. So the android low ram page(http://developer.android.com/training/articles/memory.html) suggests us to alloc/free objects at same time for more continuous memory, and this looks like Generational memory management by hand(http://developer.android.com/training/articles/memory.html#AllocatingRAM).

User code memory leak can be analysis by MAT tool. Trying to understand Dalvikvm and memory leaks




回答2:


There is very few memory leak bugs in the runtime, basically because there is very few collections which are the main source of such bugs.

You would use a memory profile to find such a memory leak. You can use VisualVM for small heap dumps but for larger heaps I use a commercial profiler like YourKit.




回答3:


If you are using a well established language/virtual machine then leaks due to "bugs in the runtime" are extremely unlikely. Spend your time looking for misuse of references in your application code.



来源:https://stackoverflow.com/questions/23476263/types-of-memory-leaks-in-a-garbage-collected-language-running-in-virtual-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!