Android: AlertDialog causes a memory leak

前端 未结 4 613
天命终不由人
天命终不由人 2020-12-05 05:47

My application shows an AlertDialog with a ListView inside. Everything worked fine bun then I decided to test this for memory leaks. After running

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 06:18

    I had run your code and when I first press the button it is showing the LeakedActivity with dialog and onClick it is removing dialog but the activity remains in foreground with black screen. On pressing back key and then again starting the activity it is showing the memory out of error exception:

    ERROR/AndroidRuntime(263): java.lang.OutOfMemoryError
    

    Then I removed the line private final byte[] junk = new byte[10*1024*1024]; from the dialog code after that no such problem exists....don't know why if anyone can put this thing in words, thanks to him/her..

    I tested the code in emulator android 2.1
    

提交回复
热议问题