Android Context Memory Leak ListView due to AudioManager

后端 未结 8 1812
走了就别回头了
走了就别回头了 2020-12-15 05:24

I have a ListView and I would expect it to be cleared from memory when the activity finishes. However, it appears that it is leaking. When I check the Memory Du

相关标签:
8条回答
  • 2020-12-15 05:52

    There are several references to AudioManager in your code that you don't create actively. E.g. each clickable View might have one to play onClick sounds [source]. I guess that is the link.

    The code looks like it would not create references to AudioManager if you disable the click sounds in your Settings. You could try that and check if there is still a leak.

    The reason for your leak might be that you are holding onto some View object in your ListView (Adapter?) code. If you keep them around then you might have a View that has an AudioManager reference and that keeps a Context reference)

    0 讨论(0)
  • 2020-12-15 05:56

    I had this same issue but it went away after following the below advice.

    Mr Guy recommends not doing heap dumps in the debugger and causing a few GCs before getting the dump. https://groups.google.com/forum/?fromgroups=#!topic/android-developers/ew6lfZUH0z8

    0 讨论(0)
提交回复
热议问题