Does the garbage collector work on static variables or methods in java?

后端 未结 4 1163
无人共我
无人共我 2020-12-02 00:17

I am creating a sample demo program for make me understand that how can I deallocate the reference of static variables, methods in java using garbage collector?

I a

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

    Other than the program, to answer your question

    1. No. Methods are not garbage collected because they don't exist in the heap in the first place.

    2. Static variables belong to the Class instance and will not be garbage collected once loaded (for most of the general Classloaders)

提交回复
热议问题