java garbage collecting in dialog

前端 未结 2 1721
北恋
北恋 2021-02-09 06:49

*I\'m now encountering a very strange java GC problem when I trying to make a button in a JFrame, and when I click the button, it display a JDialog which need to deal with and s

2条回答
  •  梦如初夏
    2021-02-09 07:09

    You're allocating new int[40000000] before while tmp still holds the reference to the last int[40000000].
    The order of operation in an expression like tmp = new int[40000] is:

    1. new int[40000]
    2. Assign the reference to the array to tmp

    So in 1. tmp is still holding the reference to it's last value.

    Try doing:

    tmp = null;
    tmp = new int[40000000];
    

提交回复
热议问题